J
Jeff
hey
asp.net 2.0
Below I'm trying to specify a ButtonField. The problem is that when I click
on the ButtonField (CommandName = UserName) I don't get info the UserName in
the gvwUsers_RowCommand. In the code below I'm trying to assign a variable
the value of "UserName" column (string username = gridRow.Cells[0].Text
but the variable get set to ""...
I need the value of UserName so can use it in a URL
Any suggestions?
<Columns>
<asp:ButtonField HeaderText="UserName" CommandName="UserName"
DataTextField="UserName" />
<asp:ButtonField HeaderText="Occupation" CommandName="Occupation"
DataTextField="Occupation" />
<asp:ButtonField HeaderText="Country" CommandName="Country" />
</Columns>
protected void gvwUsers_RowCommand(Object sender, GridViewCommandEventArgs
e)
{
if (e.CommandName == "UserName")
{
int index = Convert.ToInt32(e.CommandArgument);
GridViewRow gridRow = gvwUsers.Rows[index];
string username = gridRow.Cells[0].Text;
Response.Redirect("~/User.aspx?user=" + username);
}
}
asp.net 2.0
Below I'm trying to specify a ButtonField. The problem is that when I click
on the ButtonField (CommandName = UserName) I don't get info the UserName in
the gvwUsers_RowCommand. In the code below I'm trying to assign a variable
the value of "UserName" column (string username = gridRow.Cells[0].Text
but the variable get set to ""...
I need the value of UserName so can use it in a URL
Any suggestions?
<Columns>
<asp:ButtonField HeaderText="UserName" CommandName="UserName"
DataTextField="UserName" />
<asp:ButtonField HeaderText="Occupation" CommandName="Occupation"
DataTextField="Occupation" />
<asp:ButtonField HeaderText="Country" CommandName="Country" />
</Columns>
protected void gvwUsers_RowCommand(Object sender, GridViewCommandEventArgs
e)
{
if (e.CommandName == "UserName")
{
int index = Convert.ToInt32(e.CommandArgument);
GridViewRow gridRow = gvwUsers.Rows[index];
string username = gridRow.Cells[0].Text;
Response.Redirect("~/User.aspx?user=" + username);
}
}