如何根据ASP.NET中的checkBox访问GridView行的值计算器
问题描述:
嗨,我有一个GridView,具有多行和多列。我也在网格视图中添加了一个复选框。如何根据ASP.NET中的checkBox访问GridView行的值计算器
但是现在我遇到了访问其checkBox(es)被选中的特定行的值的麻烦。
因为按下按钮,我想要将一列的值从未注册改为注册。
另一个按钮应该将检查行的帐户ID转发到另一个页面,其中输入的所有细节将被输出。
有谁知道该怎么做?
这里的代码段我使用:
提斯是GridView控件的代码和按钮:
<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" />
<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
答
要查找的GridView检查行:
foreach (DataGridViewRow row in GridView1.Rows)
{
Checkbox cbox = (Checkbox)row.FindControl("myCheckBox");
if(cbox.Checked)
{
// do your stuff ...
}
else
{ // do your other stuff ... }
}
循环通过GridView行,找到** myCheckBox **每一行,看它是否已选中与否,这里有一个例子 - HTTP: //stackoverflow.com/questions/14995776/how-can-i-delete-the-selected-rows-checkbox-used-from-the-gridview-on-click-of/14995982#14995982 – 2013-02-25 08:46:23