在单击效果上,两个girdview我都只需要一个gridview [英] On single click effect both girdview i want only one gridview

查看:45
本文介绍了在单击效果上,两个girdview我都只需要一个gridview的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是设计.aspx页面的源代码.三个sqlconnection占用三个数据源和三个gridview
主要问题是,当我看到gridview时,它显示两个gridview请告诉我如何创建Parentgridview rowediting事件.

It is source code of design .aspx page.three sqlconnection take three datasource and three gridview
Main problem is that when i what see gridview it showing two gridview Please Tell how can i created the Parentgridview rowediting event .???

               <asp:SqlDataSource ID="SqlDataSource1" runat="server"
                   ConnectionString="<%$ ConnectionStrings:JAPITConnectionString %>"
                   SelectCommand="SELECT * FROM [viewyn]">



               <asp:GridView ID="ParentGridView" runat="server"
               AutoGenerateColumns="False"
               DataSourceID="SqlDataSource1" DataKeyNames="l_no"

                   onrowediting="ParentGridView_OnRowEditing"
                   onselectedindexchanged="ParentGridView_SelectedIndexChanged">
 <columns>
    <asp:TemplateField HeaderText="Letter Number">
       <itemtemplate>
          <asp:Label id="l_no" Runat="Server"
          Text=''<%# Eval("l_no") %>''/>
                   </itemtemplate>


    <asp:TemplateField HeaderText="name Department">
       <itemtemplate>
          <asp:Label id="nam_dep" Runat="Server"
          Text=''<%# Eval("nam_dep") %>''/>
                   </itemtemplate>


   <asp:TemplateField HeaderText="number  DEO">
       <itemtemplate>
           <asp:Label id="no_deo" Runat="Server"
           Text=''<%# Eval("no_deo") %>''/>
                   </itemtemplate>

               <asp:TemplateField HeaderText="number month">
       <itemtemplate>
           <asp:Label id="no_mon" Runat="Server"
           Text=''<%# Eval("no_mon") %>''/>
                   </itemtemplate>


               <asp:TemplateField HeaderText="Letter y/n">
       <itemtemplate>
           <asp:Label id="le_yn" Runat="Server"
           Text=''<%# Eval("le_yn") %>''/>
                   </itemtemplate>


               <asp:TemplateField HeaderText="Draft y/n">
       <itemtemplate>
           <asp:Label id="dd_yn" Runat="Server"
           Text=''<%# Eval("dd_yn") %>''/>
                   </itemtemplate>







   <asp:TemplateField HeaderText="View">
       <itemtemplate>
           <asp:Button ID="ViewChild_Button"
                 runat="server" Text="+"   CommandName="Edit" />
                   </itemtemplate>
      <edititemtemplate>
           <asp:Button ID="CancelChild_Button"
                 runat="server" Text="-" CommandName="Cancel" />
                           <asp:GridView ID="GrandChildGridView" runat="server"
     AllowPaging="true" PageSize="4"
     DataSourceID="SqlDataSource2">

                   </edititemtemplate>



  <asp:TemplateField HeaderText="View2">
       <itemtemplate>
           <asp:Button ID="ViewChild_Button1"
                 runat="server" Text="+"   CommandName="Edit" />
                   </itemtemplate>
      <edititemtemplate>
           <asp:Button ID="CancelChild_Button1"
                 runat="server" Text="-" CommandName="Cancel" />
                  <asp:GridView ID="GrandChildGridView1" runat="server"
     AllowPaging="true" PageSize="4"
     DataSourceID="SqlDataSource3">


                   </edititemtemplate>




</columns>




               <asp:SqlDataSource ID="SqlDataSource3" runat="server"
                   ConnectionString="<%$ ConnectionStrings:JAPITConnectionString %>"
                   SelectCommand="SELECT * FROM [entry_dd] WHERE ([l_no] = @l_no)">
                   <SelectParameters>
                       <asp:SessionParameter Name="l_no" SessionField="l_no" Type="String" />
                   </SelectParameters>




               <br />
               <asp:SqlDataSource ID="SqlDataSource2" runat="server"
                   ConnectionString="<%$ ConnectionStrings:JAPITConnectionString %>"
                   SelectCommand="SELECT * FROM [Letter_dept] WHERE ([l_no] = @l_no)">
                   <SelectParameters>
                       <asp:SessionParameter Name="l_no" SessionField="l_no" Type="String" />
                   </SelectParameters>









protected void ParentGridView_OnRowEditing(object sender,GridViewEditEventArgs e)
    {

      
        int parent_index = e.NewEditIndex;

        //to set the edit index of the Parent 
        //grid with that of the current row
        ParentGridView.EditIndex = parent_index;
        ParentGridView.DataBind();
        //find the pubid_lbl containing pub_id in that 
        //particular row by using findcontrol method
        GridViewRow row = ParentGridView.Rows[parent_index];
        Label l_nu = (Label)row.FindControl("l_no");

        //save pub_id and edit_index in session for childgridview''s use
        Session["l_no"] = l_nu.Text;
        Session["ParentGridViewIndex"] = parent_index;
        
    }

推荐答案

ConnectionStrings:JAPITConnectionString%> SelectCommand ="SELECT * FROM [viewyn]"> < asp:GridView ID ="ParentGridView" runat =服务器" AutoGenerateColumns ="False" DataSourceID ="SqlDataSource1" DataKeyNames ="l_no" onrowediting ="ParentGridView_OnRowEditing" onselectedindexchanged ="ParentGridView_SelectedIndexChanged"> <列> < asp:TemplateField HeaderText =字母数字"> < itemtemplate> < asp:标签id ="l_no" Runat =服务器" Text =''<%#Eval("l_no")%>''/> </itemtemplate> < asp:TemplateField HeaderText =名称部门"> < itemtemplate> < asp:标签id ="nam_dep" Runat =服务器" Text =''<%#Eval("nam_dep")%>''/> </itemtemplate> < asp:TemplateField HeaderText =数字DEO"> < itemtemplate> < asp:标签id ="no_deo" Runat =服务器" Text =''<%#Eval("no_deo")%>''/> </itemtemplate> < asp:TemplateField HeaderText =数字月份"> < itemtemplate> < asp:标签id ="no_mon" Runat =服务器" Text =''<%#Eval("no_mon")%>''/> </itemtemplate> < asp:TemplateField HeaderText =字母y/n"> < itemtemplate> < asp:标签id ="le_yn" Runat =服务器" Text =''<%#Eval("le_yn")%>''/> </itemtemplate> < asp:TemplateField HeaderText =草稿y/n"> < itemtemplate> < asp:标签id ="dd_yn" Runat =服务器" Text =''<%#Eval("dd_yn")%>''/> </itemtemplate> < asp:TemplateField HeaderText ="View"> < itemtemplate> < asp:Button ID ="ViewChild_Button" runat ="server" Text ="+" CommandName ="Edit"/> </itemtemplate> < edititemtemplate> < asp:Button ID ="CancelChild_Button" runat ="server" Text =-" CommandName ="Cancel"/> < asp:GridView ID ="GrandChildGridView" runat =服务器" AllowPaging ="true" PageSize ="4" DataSourceID ="SqlDataSource2"> </edititemtemplate> < asp:TemplateField HeaderText ="View2"> < itemtemplate> < asp:Button ID ="ViewChild_Button1" runat ="server" Text ="+" CommandName ="Edit"/> </itemtemplate> < edititemtemplate> < asp:Button ID ="CancelChild_Button1" runat ="server" Text =-" CommandName ="Cancel"/> < asp:GridView ID ="GrandChildGridView1" runat =服务器" AllowPaging ="true" PageSize ="4" DataSourceID ="SqlDataSource3"> </edititemtemplate> </列> < asp:SqlDataSource ID ="SqlDataSource3" runat =服务器" ConnectionString =<%
ConnectionStrings:JAPITConnectionString %>" SelectCommand="SELECT * FROM [viewyn]"> <asp:GridView ID="ParentGridView" runat="server" AutoGenerateColumns="False" DataSourceID="SqlDataSource1" DataKeyNames="l_no" onrowediting="ParentGridView_OnRowEditing" onselectedindexchanged="ParentGridView_SelectedIndexChanged"> <columns> <asp:TemplateField HeaderText="Letter Number"> <itemtemplate> <asp:Label id="l_no" Runat="Server" Text=''<%# Eval("l_no") %>''/> </itemtemplate> <asp:TemplateField HeaderText="name Department"> <itemtemplate> <asp:Label id="nam_dep" Runat="Server" Text=''<%# Eval("nam_dep") %>''/> </itemtemplate> <asp:TemplateField HeaderText="number DEO"> <itemtemplate> <asp:Label id="no_deo" Runat="Server" Text=''<%# Eval("no_deo") %>''/> </itemtemplate> <asp:TemplateField HeaderText="number month"> <itemtemplate> <asp:Label id="no_mon" Runat="Server" Text=''<%# Eval("no_mon") %>''/> </itemtemplate> <asp:TemplateField HeaderText="Letter y/n"> <itemtemplate> <asp:Label id="le_yn" Runat="Server" Text=''<%# Eval("le_yn") %>''/> </itemtemplate> <asp:TemplateField HeaderText="Draft y/n"> <itemtemplate> <asp:Label id="dd_yn" Runat="Server" Text=''<%# Eval("dd_yn") %>''/> </itemtemplate> <asp:TemplateField HeaderText="View"> <itemtemplate> <asp:Button ID="ViewChild_Button" runat="server" Text="+" CommandName="Edit" /> </itemtemplate> <edititemtemplate> <asp:Button ID="CancelChild_Button" runat="server" Text="-" CommandName="Cancel" /> <asp:GridView ID="GrandChildGridView" runat="server" AllowPaging="true" PageSize="4" DataSourceID="SqlDataSource2"> </edititemtemplate> <asp:TemplateField HeaderText="View2"> <itemtemplate> <asp:Button ID="ViewChild_Button1" runat="server" Text="+" CommandName="Edit" /> </itemtemplate> <edititemtemplate> <asp:Button ID="CancelChild_Button1" runat="server" Text="-" CommandName="Cancel" /> <asp:GridView ID="GrandChildGridView1" runat="server" AllowPaging="true" PageSize="4" DataSourceID="SqlDataSource3"> </edititemtemplate> </columns> <asp:SqlDataSource ID="SqlDataSource3" runat="server" ConnectionString="<%


ConnectionStrings:JAPITConnectionString%>" SelectCommand ="SELECT * FROM [entry_dd]在([l_no] = @l_no)"> < SelectParameters> < asp:SessionParameter名称="l_no" SessionField ="l_no" Type ="String"/> </SelectParameters> < br/> < asp:SqlDataSource ID ="SqlDataSource2" runat =服务器" ConnectionString =<%
ConnectionStrings:JAPITConnectionString %>" SelectCommand="SELECT * FROM [entry_dd] WHERE ([l_no] = @l_no)"> <SelectParameters> <asp:SessionParameter Name="l_no" SessionField="l_no" Type="String" /> </SelectParameters> <br /> <asp:SqlDataSource ID="SqlDataSource2" runat="server" ConnectionString="<%


ConnectionStrings:JAPITConnectionString%>" SelectCommand ="SELECT * FROM [Letter_dept] WHERE([l_no] = @l_no)"> < SelectParameters> < asp:SessionParameter名称="l_no" SessionField ="l_no" Type ="String"/> </SelectParameters>
ConnectionStrings:JAPITConnectionString %>" SelectCommand="SELECT * FROM [Letter_dept] WHERE ([l_no] = @l_no)"> <SelectParameters> <asp:SessionParameter Name="l_no" SessionField="l_no" Type="String" /> </SelectParameters>









protected void ParentGridView_OnRowEditing(object sender,GridViewEditEventArgs e)
    {

      
        int parent_index = e.NewEditIndex;

        //to set the edit index of the Parent 
        //grid with that of the current row
        ParentGridView.EditIndex = parent_index;
        ParentGridView.DataBind();
        //find the pubid_lbl containing pub_id in that 
        //particular row by using findcontrol method
        GridViewRow row = ParentGridView.Rows[parent_index];
        Label l_nu = (Label)row.FindControl("l_no");

        //save pub_id and edit_index in session for childgridview''s use
        Session["l_no"] = l_nu.Text;
        Session["ParentGridViewIndex"] = parent_index;
        
    }


这篇关于在单击效果上,两个girdview我都只需要一个gridview的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆