Reputation: 2364
I have a 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>
Where the code behind for 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.
}
On debugging I can get to the checkBox changed event, however need to retrieve the string from the profileName
cell from its respective row cell.
I tried something like this -
string c = row.Cells("profileName").value.toString();
However this did not work, how can I get the string?
Upvotes: 0
Views: 1921
Reputation: 1
you can give like
Ex : you can straight away give like ;
string profilename = gridview.Rows[0].Cells[1].Text;
Upvotes: 0
Reputation: 460068
If you use a BoundField
you need to use Cells[index].Text
. Since it's in the third column:
string profileName = row.Cells[2].Text;
Upvotes: 4