gridview内部gridview [英] gridview inside gridview

查看:70
本文介绍了gridview内部gridview的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
    <table style="width: 100%">
        <tr>
            <td>
                <br />
                <asp:ScriptManager ID="ScriptManager1" runat="server">
                 
                <asp:UpdatePanel ID="UpdatePanel1" runat="server">
                    <contenttemplate>
                        <asp:GridView ID="GridView1" runat="server" 
    AutoGenerateColumns="False" DataSourceID="SqlDataSource1" 
    onrowdatabound="GridView1_RowDataBound" Width="244px">
                            <columns>
                                <asp:BoundField DataField="l_no" HeaderText="l_no" 
            SortExpression="l_no" />
                                <asp:BoundField DataField="nam_dep" HeaderText="nam_dep" 
            SortExpression="nam_dep" />
                                <asp:BoundField DataField="no_deo" HeaderText="no_deo" 
            SortExpression="no_deo" />
                                <asp:BoundField DataField="no_mon" HeaderText="no_mon" 
            SortExpression="no_mon" />
                                <asp:BoundField DataField="le_yn" HeaderText="le_yn" 
            SortExpression="le_yn" />
                                <asp:BoundField DataField="dd_yn" HeaderText="dd_yn" 
            SortExpression="dd_yn" />
                            </columns>
                            <emptydatatemplate>
                                <asp:LinkButton ID="LinkButton11" runat="server" 
            Font-Size="X-Large" Font-Underline="False" onclick="LinkButton1_Click ">+
                                <asp:Panel ID="Panel3" runat="server" Height="127px" 
            Visible="False">
                                    <asp:GridView ID="GridView2" runat="server" 
                AutoGenerateColumns="False" DataSourceID="SqlDataSource2">
                                        <columns>
                                            <asp:BoundField DataField="req_id" HeaderText="req_id" 
                        InsertVisible="False" ReadOnly="True" SortExpression="req_id" />
                                            <asp:BoundField DataField="l_no" HeaderText="l_no" 
                        SortExpression="l_no" />
                                            <asp:BoundField DataField="nam_dep" HeaderText="nam_dep" 
                        SortExpression="nam_dep" />
                                            <asp:BoundField DataField="date" HeaderText="date" 
                        SortExpression="date" />
                                            <asp:BoundField DataField="no_deo" HeaderText="no_deo" 
                        SortExpression="no_deo" />
                                            <asp:BoundField DataField="no_mon" HeaderText="no_mon" 
                        SortExpression="no_mon" />
                                        </columns>
                                    
                                    <asp:SqlDataSource ID="SqlDataSource2" runat="server" 
                ConnectionString="<%$ ConnectionStrings:ConnectionString %>" 
                SelectCommand="SELECT * FROM [request_dept] WHERE ([l_no] = @l_no)">
                                        <SelectParameters>
                                            <asp:Parameter Name="l_no" Type="String" />
                                        </SelectParameters>
                                    
                                
                            </emptydatatemplate>
                        
                        <asp:SqlDataSource ID="SqlDataSource1" runat="server" 
                            ConnectionString="<%$ ConnectionStrings:ConnectionString %>" 
                            SelectCommand="SELECT * FROM [viewyn]">
                    </contenttemplate>
                
                
            </td>
        </tr>
        <tr>
            <td>
                <asp:Button ID="Button1" runat="server" Text="Button" onclick="Button1_Click" />
                
               
            </td>
        </tr>
    </table>

public partial class trygrid : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        
        
        
    }
    protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            SqlDataSource s = (SqlDataSource)e.Row.FindControl("SqlDataSource2");
            s.SelectParameters[0].DefaultValue = e.Row.Cells[1].Text;
        }

    }
    protected void LinkButton1_Click(object sender, EventArgs e)
    {
        LinkButton l_btn =   (LinkButton)sender;
        GridViewRow gvr = (GridViewRow)l_btn.NamingContainer;
    Panel p1 =   (Panel)gvr.FindControl("Panel3");
    LinkButton lb1 =   (LinkButton)gvr.FindControl("LinkButton1");
    if (p1.Visible == false)
    {
        p1.Visible = true;
        lb1.Text = "-";
    }
    else if (p1.Visible == true)
    {
        p1.Visible = false;
        lb1.Text = "+";
    }

    GridView gv2 =   (GridView)l_btn.FindControl("GridView2");
    gv2.DataBind();



    }
    protected void Button1_Click(object sender, EventArgs e)
    {

    }
}

推荐答案

ConnectionStrings:ConnectionString%>" SelectCommand = " > < SelectParameters> < asp:参数名称= " Type = " /> </ SelectParameters > </ emptydatatemplate > < asp:SqlDataSource ID = " runat = " ConnectionString = "
ConnectionStrings:ConnectionString %>" SelectCommand="SELECT * FROM [request_dept] WHERE ([l_no] = @l_no)"> <SelectParameters> <asp:Parameter Name="l_no" Type="String" /> </SelectParameters> </emptydatatemplate> <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%


ConnectionStrings:ConnectionString%>" SelectCommand = " > </ contenttemplate > </ td > </ tr > < tr> < td> < asp:Button ID = " runat = " Text = " onclick = " /> </ td > </ tr > </ > 公共 部分 class trygrid:System.Web .UI.页面 { 受保护的 无效 Page_Load(对象发​​件人,EventArgs e) { } 受保护的 无效 GridView1_RowDataBound(对象发​​件人,GridViewRowEventArgs e) { 如果(例如,Row.RowType == DataControlRowType.DataRow) { SqlDataSource s =(SqlDataSource)e.Row.FindControl(" ); s.SelectParameters [ 0 ].DefaultValue = e.Row.Cells [ 1 ].Text; } } 受保护的 无效 LinkBut​​ton1_Click(对象发​​件人,EventArgs e) { LinkBut​​ton l_btn =(LinkBut​​ton)发送器; GridViewRow gvr =(GridViewRow)l_btn.NamingContainer; 面板p1 =(Panel)gvr.FindControl(" ); LinkBut​​ton lb1 =(LinkBut​​ton)gvr.FindControl(" ); 如果(p1.Visible == false ) { p1.Visible = true ; lb1.Text = " ; } 其他 如果(p1.Visible == true ) { p1.Visible = false ; lb1.Text = " ; } GridView gv2 =(GridView)l_btn.FindControl(" ); gv2.DataBind(); } 受保护的 无效 Button1_Click(对象发​​件人,EventArgs e) { } }
ConnectionStrings:ConnectionString %>" SelectCommand="SELECT * FROM [viewyn]"> </contenttemplate> </td> </tr> <tr> <td> <asp:Button ID="Button1" runat="server" Text="Button" onclick="Button1_Click" /> </td> </tr> </table> public partial class trygrid : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { } protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e) { if (e.Row.RowType == DataControlRowType.DataRow) { SqlDataSource s = (SqlDataSource)e.Row.FindControl("SqlDataSource2"); s.SelectParameters[0].DefaultValue = e.Row.Cells[1].Text; } } protected void LinkButton1_Click(object sender, EventArgs e) { LinkButton l_btn = (LinkButton)sender; GridViewRow gvr = (GridViewRow)l_btn.NamingContainer; Panel p1 = (Panel)gvr.FindControl("Panel3"); LinkButton lb1 = (LinkButton)gvr.FindControl("LinkButton1"); if (p1.Visible == false) { p1.Visible = true; lb1.Text = "-"; } else if (p1.Visible == true) { p1.Visible = false; lb1.Text = "+"; } GridView gv2 = (GridView)l_btn.FindControl("GridView2"); gv2.DataBind(); } protected void Button1_Click(object sender, EventArgs e) { } }


尝试以下代码项目-常见问题系列1:ASP.Net GridView [ ^ ].


这篇关于gridview内部gridview的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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