关闭

gridview模板列绑定gridview

标签: aspserverobjectlistdiv
4081人阅读 评论(0) 收藏 举报
分类:
<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

0
0

查看评论
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
    个人资料
    • 访问:56697次
    • 积分:1056
    • 等级:
    • 排名:千里之外
    • 原创:49篇
    • 转载:4篇
    • 译文:0篇
    • 评论:12条
    文章分类
    最新评论