ttt2的专栏

水的世界

gridview模板列绑定gridview
<form id="form1" runat="server">
    <div>
        <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:NorthwindConnectionString %>"
            SelectCommand="SELECT top 5 [ProductID], [ProductName] FROM [Alphabetical list of products]">
        </asp:SqlDataSource>
        &nbsp; &nbsp;&nbsp;&nbsp;<br />
        &nbsp;<asp:SqlDataSource ID="SqlDataSource2" runat="server" ConnectionString="<%$ ConnectionStrings:NorthwindConnectionString %>"
            SelectCommand="SELECT  * FROM [Order Details] where productid=@id">
        </asp:SqlDataSource>
                    </div>
        <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" DataKeyNames="ProductID"
            DataSourceID="SqlDataSource1">
            <Columns>
                <asp:BoundField DataField="ProductID" HeaderText="ProductID" InsertVisible="False"
                    ReadOnly="True" SortExpression="ProductID" />
                <asp:BoundField DataField="ProductName" HeaderText="ProductName" SortExpression="ProductName" />
                <asp:TemplateField HeaderText="detail">
                    <ItemTemplate>
                        &nbsp;&nbsp;&nbsp;
                        <asp:GridView ID="GridView2" runat="server">
                        </asp:GridView>
                    </ItemTemplate>
                </asp:TemplateField>
            </Columns>
        </asp:GridView>
    </form>

 

    Protected Sub GridView1_RowDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles GridView1.RowDataBound
        If e.Row.RowType = DataControlRowType.DataRow Then
            SqlDataSource2.SelectParameters.Clear()

            SqlDataSource2.SelectParameters.Add("id", e.Row.Cells(0).Text)
            'SqlDataSource2.DataBind()
            Dim g As GridView
            g = e.Row.Cells(2).FindControl("gridview2")
            g.DataSource = Me.SqlDataSource2
            g.DataBind()

        End If
    End Sub

阅读更多
个人分类: asp.net
想对作者说点什么? 我来说一句

没有更多推荐了,返回首页

不良信息举报

gridview模板列绑定gridview

最多只允许输入30个字

加入CSDN,享受更精准的内容推荐,与500万程序员共同成长!
关闭
关闭