我在 asp 中有一个 gridview,我在其中添加了第一列作为复选框列。现在我想选择此列并获取行的 id 值..但我不知道该怎么做..
这是我的 Aspx 代码..
<asp:GridView ID="GridView1" runat="server" OnRowDataBound="GridView1_RowDataBound"
AutoGenerateColumns="False" BackColor="LightGoldenrodYellow"
BorderColor="Tan" BorderWidth="1px" CellPadding="2" ForeColor="Black"
GridLines="None">
<AlternatingRowStyle BackColor="PaleGoldenrod" />
<Columns>
<asp:TemplateField>
<HeaderTemplate>
<asp:CheckBox ID="chkhdr" runat="server" />
</HeaderTemplate>
<ItemTemplate>
<asp:CheckBox ID="chkChild" runat="server" />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Username">
<ItemTemplate>
<asp:Label ID="Label1" runat="server" Text='<%# Eval("col0") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Role(Admin)">
<ItemTemplate>
<asp:CheckBox ID="chkAdmin" runat="server" Checked='<%# Eval("col1") %>' />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Role(User)">
<ItemTemplate>
<asp:CheckBox ID="chkUser" runat="server" Checked='<%# Eval("col2") %>' />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Role(GeneralUser)">
<ItemTemplate>
<asp:CheckBox ID="chkgen" runat="server" Checked='<%# Eval("col3") %>' />
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
这是我的文件背后的代码......
protected void BindGridviewData()
{
var role = from MembershipUser u in Membership.GetAllUsers()
select new
{
User = u.UserName,
Role = string.Join(",", Roles.GetRolesForUser(u.UserName))
};
DataTable dTable = new DataTable();
dTable.Columns.Add("col0", typeof(string));
dTable.Columns.Add("col1", typeof(bool));
dTable.Columns.Add("col2", typeof(bool));
dTable.Columns.Add("col3", typeof(bool));
foreach (MembershipUser u in Membership.GetAllUsers())
{
DataRow dRow = dTable.NewRow();
dRow[0] = u.UserName;
string[] roles = Roles.GetRolesForUser(u.UserName);
dRow[1] = roles.Contains("Admin") ? true : false;
dRow[2] = roles.Contains("DPAO User") ? true : false;
dRow[3] = roles.Contains("GeneralUser") ? true : false;
dTable.Rows.Add(dRow);
}
GridView1.DataSource = dTable;
GridView1.DataBind();
}
请大家帮助我,因为我不知道如何做到这一点......提前谢谢......