在父网格视图中看不到子GridView [英] Cannot see child gridview inside parent grid view

查看:55
本文介绍了在父网格视图中看不到子GridView的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

请给个主意.我全力以赴.在此先感谢您.

Kindly please give idea . I applied all my effort in it . Thanking u in advance .

<%@ Page Language="C#" MasterPageFile="~/Admin.master" AutoEventWireup="true" CodeFile="try3.aspx.cs" Inherits="try3" Title="Untitled Page" %>

<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
    <br />
    <table style="width: 100%">
        <tr>
            <td style="height: 22px">
                <asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>
                 
                <asp:GridView ID="ParentGridView" runat="server"

                AutoGenerateColumns="False"

                DataSourceID="SqlDataSource1" DataKeyNames="l_no" 

                    onselectedindexchanged="ParentGridView_SelectedIndexChanged">
  <Columns>
     <asp:TemplateField HeaderText="Letter Number">
        <ItemTemplate>
           <asp:Label id="l_no" Runat="Server" 

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

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

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

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

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

            Text='<%# Eval("dd_yn") %>'/>
                    </ItemTemplate>
    </asp:TemplateField>
    <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">
</asp:GridView>
                    </EditItemTemplate>
   </asp:TemplateField>
 </Columns>
</asp:GridView>
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:ABCConnectionString  %>"  SelectCommand="SELECT * FROM [viewyn]"></asp:SqlDataSource>
                <br />
<asp:SqlDataSource ID="SqlDataSource2" runat="server" ConnectionString="<%$ ConnectionStrings:ABCConnectionString  %>"  SelectCommand="SELECT * FROM [Letter_dept] WHERE ([l_no] = @l_no)"> <SelectParameters>                 <asp:SessionParameter Name="l_no" SessionField="l_no" Type="String" /></SelectParameters>                </asp:SqlDataSource>

            </td>
            <td style="height: 22px">
            </td>
        </tr>
        <tr>
            <td>
                 </td>
            <td>
                 </td>
        </tr>
        <tr>
            <td>
                 </td>
            <td>
                 </td>
        </tr>
        <tr>
            <td>
                 </td>
            <td>
                 </td>
        </tr>
    </table>
</asp:Content>


using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;

public partial class try3 : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    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;
    }

    protected void ParentGridView_SelectedIndexChanged(object sender, EventArgs e)
    {

    }
}

推荐答案

ConnectionStrings:ABCConnectionString %> " SelectCommand =" > /asp:SqlDataSource < br > < asp:SqlDataSource ID =" runat 服务器" ConnectionString <%
ConnectionStrings:ABCConnectionString %>" SelectCommand="SELECT * FROM [viewyn]"></asp:SqlDataSource> <br /> <asp:SqlDataSource ID="SqlDataSource2" runat="server" ConnectionString="<%


ConnectionStrings:ABCConnectionString %> " SelectCommand =" > < SelectParameters > < asp:SessionParameter 名称 =" SessionField =" 类型 =" 字符串" / > < /SelectParameters > /asp:SqlDataSource < /td > < td =" 高度:22px" < /td > < /tr > < tr > < td > < /td > < td > < /td > < /tr > < tr > < td > < /td > < td > < /td > < /tr > < tr > < td > < /td > < td > < /td > < /tr > < /table > < /asp:Content >
ConnectionStrings:ABCConnectionString %>" SelectCommand="SELECT * FROM [Letter_dept] WHERE ([l_no] = @l_no)"> <SelectParameters> <asp:SessionParameter Name="l_no" SessionField="l_no" Type="String" /></SelectParameters> </asp:SqlDataSource> </td> <td style="height: 22px"> </td> </tr> <tr> <td>  </td> <td>  </td> </tr> <tr> <td>  </td> <td>  </td> </tr> <tr> <td>  </td> <td>  </td> </tr> </table> </asp:Content>


using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;

public partial class try3 : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    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;
    }

    protected void ParentGridView_SelectedIndexChanged(object sender, EventArgs e)
    {

    }
}


我在想您的参数类型可能不正确? 就是为了澄清" ..
无论如何,我之前所做的是通常在后面编写代码以将参数附加到sqldatasource,以将参数正确地附加到它.有关详细信息,请参考以下链接:

> http://stackoverflow.com/questions/485821/how-to-将变量传递给sql数据源的选择命令 [ ^ ]
What I am thinking maybe your parameter type is incorrect? "that''s for clarification"..
Anywayz, what i did before is i usually write a code behind to attach the parameter to sqldatasource to properly attach the parameter to it. for details you may refer to this link:

http://stackoverflow.com/questions/485821/how-to-pass-variable-to-selectcommand-of-sqldatasource[^]


这篇关于在父网格视图中看不到子GridView的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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