0

嗨,我有一个包含多行和多列的 GridView。我还在网格视图中添加了一个复选框..

但是现在我在访问检查了复选框的特定行的值时遇到了麻烦。

因为按下按钮后,我想将一列的值从未注册更改为已注册。

另一个按钮 应该将选中行的帐户 ID 转发到另一个页面,该页面将输出条目的所有详细信息。

有谁知道这是怎么做到的吗?

这是我正在使用的代码段:

Tis 是 GridView 和 Button 的代码:

<asp:GridView ID="GridView1" runat="server" CellPadding="4" ForeColor="#333333" 
        GridLines="None" Width="1500px">
        <Columns>

                    <asp:TemplateField >
                        <ItemTemplate>
                            <asp:CheckBox ID="myCheckBox" runat="server" />
                        </ItemTemplate>
                    </asp:TemplateField>

              </Columns>
        <AlternatingRowStyle BackColor="White" />
        <EditRowStyle BackColor="#2461BF" />
        <FooterStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
        <HeaderStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
        <PagerStyle BackColor="#2461BF" ForeColor="White" HorizontalAlign="Center" />
        <RowStyle BackColor="#EFF3FB" />
        <SelectedRowStyle BackColor="#D1DDF1" Font-Bold="True" ForeColor="#333333" />
        <SortedAscendingCellStyle BackColor="#F5F7FB" />
        <SortedAscendingHeaderStyle BackColor="#6D95E1" />
        <SortedDescendingCellStyle BackColor="#E9EBEF" />
        <SortedDescendingHeaderStyle BackColor="#4870BE" />
    </asp:GridView>


     <asp:Button ID="DetailsBtn" runat="server" Text="See Details" />
     &nbsp; &nbsp; &nbsp; &nbsp;
     <asp:Button ID="RegBtn" runat="server" Text="Mark Registered" />

这是填充 GridView 的代码

Try
        myconn.Open()
        Dim sqlstring As String = "SELECT a.account_id AS 'No', a.accountid_number .BLA BLA BLA"
        Dim smd As MySqlCommand
        smd = New MySqlCommand(sqlstring, myconn)
        smd.CommandType = CommandType.Text

        Dim da As New MySqlDataAdapter(smd)
        Dim cb As New MySqlCommandBuilder(da)
        Dim ds As New DataSet()
        da.Fill(ds)

        GridView1.DataSource = ds.Tables(0)
        GridView1.DataBind()

        myconn.Close()
    Catch ex As Exception
        'System.Diagnostics.Debug.WriteLine(ex.ToString())
        Dim exmess As String = "alert('" & ex.Message.ToString() & "')"
        Page.ClientScript.RegisterStartupScript(Me.GetType(), "ErrorAlert", exmess, True)
        myconn.Close()
    End Try

我应该为这里的按钮做什么?

Protected Sub RegBtn_Click(ByVal sender As Object, ByVal e As EventArgs) Handles RegBtn.Click

End Sub
4

1 回答 1

2

要在 gridview 中查找选中的行:

foreach (DataGridViewRow row in GridView1.Rows)
{
 Checkbox cbox = (Checkbox)row.FindControl("myCheckBox");
 if(cbox.Checked)
 {
   // do your stuff ...
 }
 else
 { // do your other stuff ... }
}
于 2013-02-25T08:48:24.417 回答