关闭

gridview模板列加htmlinputcheckbox的取值

1183人阅读 评论(0) 收藏 举报

        Dim i As Integer
        Dim str1 As String
        Dim t As HtmlInputCheckBox
        str1 = ""
        For i = 0 To GridView1.Rows.Count - 1

            t = GridView1.Rows(i).Cells(6).FindControl("Checkbox1")
            If t.Checked Then
                If str1 = "" Then
                    str1 = t.Value
                Else
                    str1 = str1 & "," & t.Value
                End If

            End If
        Next
        Label1.Text = str1

 

<body>
    <form id="form1" runat="server">
    <div>
        &nbsp;<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:NorthwindConnectionString %>"
            SelectCommand="SELECT [OrderID], [ProductID], [UnitPrice], [Quantity], [Discount] FROM [Order Details] WHERE ([ProductID] = @ProductID)">
            <SelectParameters>
                <asp:ControlParameter ControlID="DropDownList1" Name="ProductID" PropertyName="SelectedValue"
                    Type="Int32" />
            </SelectParameters>
        </asp:SqlDataSource>
        &nbsp;
        <asp:DropDownList ID="DropDownList1" runat="server" AutoPostBack="True" DataSourceID="SqlDataSource2"
            DataTextField="ProductName" DataValueField="ProductID">
        </asp:DropDownList>
        <asp:Button ID="Button1" runat="server" Text="Button" />
        <asp:Label ID="Label1" runat="server" Text="Label"></asp:Label><br />
        <asp:GridView ID="GridView1" runat="server" AllowPaging="True" AutoGenerateColumns="False"
            DataKeyNames="OrderID,ProductID" DataSourceID="SqlDataSource1" EmptyDataText="111">
            <Columns>
                <asp:BoundField DataField="OrderID" HeaderText="OrderID" ReadOnly="True" SortExpression="OrderID" />
                <asp:BoundField DataField="ProductID" HeaderText="ProductID" ReadOnly="True" SortExpression="ProductID" />
                <asp:BoundField DataField="UnitPrice" HeaderText="UnitPrice" SortExpression="UnitPrice" DataFormatString="{0:C}" />
                <asp:BoundField DataField="Quantity" HeaderText="Quantity" SortExpression="Quantity" />
                <asp:BoundField DataField="Discount" HeaderText="Discount" SortExpression="Discount" />
                <asp:ImageField DataImageUrlField="OrderID" DataImageUrlFormatString="/{0}.gif" HeaderText="pic">
                </asp:ImageField>
                <asp:TemplateField FooterText="id">
                    <ItemTemplate>
                        &nbsp;<input id="Checkbox1" runat="server" type="checkbox" value='<%# Eval("OrderID") %>' />
                       
                    </ItemTemplate>
                </asp:TemplateField>
            </Columns>
        </asp:GridView>
        <%=gridview1.PageIndex +1%>of<%=GridView1.PageCount%>
        <br />
   
    </div>
        <asp:SqlDataSource ID="SqlDataSource2" runat="server" ConnectionString="<%$ ConnectionStrings:NorthwindConnectionString %>"
            SelectCommand="SELECT [ProductID], [ProductName] FROM [Products]"></asp:SqlDataSource>
    </form>
</body>

 

0
0

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