我有一个 GridView -
<asp:GridView ID="table_example" Runat="server"
DataSourceID="SqlDataSource3" AutoGenerateColumns="False"
ClientIDMode="Static" onprerender="table_example_PreRender">
<Columns>
<asp:TemplateField>
<HeaderTemplate>
<asp:Label ID="Label1" runat="server" Text="Select"></asp:Label>
</HeaderTemplate>
<ItemTemplate>
<asp:CheckBox ID="chkRow" runat="server" OnCheckedChanged="CheckBoxPN_CheckedChanged" AutoPostBack="true"/>
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField HeaderText="profileID" DataField="profileID"
SortExpression="profileID"></asp:BoundField>
<asp:BoundField HeaderText="profileName" DataField="profileName"
SortExpression="profileName"></asp:BoundField>
</Columns>
</asp:GridView>
后面的代码在哪里chkRow
-
protected void CheckBoxPN_CheckedChanged(Object sender, EventArgs e)
{
CheckBox chk = (CheckBox)sender;
GridViewRow row = (GridViewRow)chk.NamingContainer;
//when a user clicks the checkbox I need the string from profileName in that row.
}
在调试时,我可以得到 checkBox changed 事件,但是需要profileName
从相应的行单元格中检索单元格中的字符串。
我试过这样的东西 -
string c = row.Cells("profileName").value.toString();
但是这不起作用,我怎样才能得到字符串?