another ButtonField Problem

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);
}
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,968
Messages
2,570,152
Members
46,697
Latest member
AugustNabo

Latest Threads

Top