Home All Groups Group Topic Archive Search About

Selecting a value from a Gridview Control

Author
6 Sep 2006 2:04 PM
hal
I'm trying to get a value from a gridview control and put that value in
a query string.  I have a select button on the gridview and once the
user hits the select button i want to capture the the userid.  Here's
some example code and you can see where i'm trying to do this in on the
line that starts with Response.Redirect:

    protected void SearchUserMenu_MenuItemClick(object sender,
MenuEventArgs e)
    {
        if (GridView1.SelectedIndex > -1)
        {
            switch (e.Item.Text)
            {
                case "Security User":
                    Response.Redirect("~/SecurityUser.aspx?userID=" +
GridView1.SelectedRow.DataItem);
                    break;
                case "WFM User Group/Location":
                    break;
                case "Maintain User":
                    break;
                case "Add User":
                    break;
            }
        }
    }


any suggestions would be great.
Thanks

Author
6 Sep 2006 10:01 PM
lwhitb1
Try this:

       GridViewRow row = GridView1.SelectedRow;
       string yourDataItem  = row.Cells[1].Text;

hal wrote:
Show quoteHide quote
> I'm trying to get a value from a gridview control and put that value in
> a query string.  I have a select button on the gridview and once the
> user hits the select button i want to capture the the userid.  Here's
> some example code and you can see where i'm trying to do this in on the
> line that starts with Response.Redirect:
>
>     protected void SearchUserMenu_MenuItemClick(object sender,
> MenuEventArgs e)
>     {
>         if (GridView1.SelectedIndex > -1)
>         {
>             switch (e.Item.Text)
>             {
>                 case "Security User":
>                     Response.Redirect("~/SecurityUser.aspx?userID=" +
> GridView1.SelectedRow.DataItem);
>                     break;
>                 case "WFM User Group/Location":
>                     break;
>                 case "Maintain User":
>                     break;
>                 case "Add User":
>                     break;
>             }
>         }
>     }
>
>
> any suggestions would be great.
> Thanks