SIGN UP MEMBER LOGIN:    
Blog

select current row from a gridview

Posted by Shyju Blogs | Current Affairs May 25, 2007
How to select current row from a gridview, retrieve the hidden coloumns value from selected gridview row.

How to get current selcted row index in GridView?

I saw many people are struggling to get the current selected row when the rowcommand event.

In asp.net 2.0 row comand will be like this

protected void gridcommand(object sender, GridViewCommandEventArgs e)

here you can't get any property like e.RowIndex  or e.Keys

But if you look at other specific event like OnRowUpdating OnRowDeleted ,properties like e.RowIndex  or e.Keys are available so it will be easy to retrieve the values.you dont have to worry about this there is work around for getting this values in the command event ,i know that if you are using Gridview then you will definetly come across situation where you need to use the command event other than normal edit update and delete events.

thfollowing code sample will help you to retrieve those

 protected void gridcommand(object sender, GridViewCommandEventArgs e)
    {
        GridViewRow row = (GridViewRow)((Control)e.CommandSource).Parent.Parent;
        GridView gv = (GridView)(e.CommandSource);
        string s = gv.DataKeys[row.RowIndex][0].ToString();
     }

 

share this blog :
post comment
 

Hi, This as as for my knowledge Firstly vl Declare method for our grid in the method vl assign or add the coulmns dynamically likely this way

private void Grid()

{

ultraWebGridOne.Columns.Add("Name", ntegration");

ultraWebGridOne.Columns.FromKey("Name").Width = (Unit)200;

ultraWebGridOne.Columns.Add("acode","GLCode" );

ultraWebGridOne.Columns.Add("aname", "GLName");

ultraWebGridOne.DisplayLayout.ClientSideEvents.BeforeEnterEditModeHandler = "BeforeEdit";

}

 

Now v should call a functon for this in Script file vr vl assign the hidden variable to it and retive the data though those hidden varaibles likely this way

in binding the data v can do like this

ultraWebGridOne.Bands[0].Columns.FromKey("XYZ").Type = hiddenXYZ.value;

ultraWebGridOne.Bands[0].Columns.FromKey("ABC").EditorControlID = hiddenABC.value;

(likley u can add the base coulmns to it vl write the event for this in this method likely the above iguess u know where to add this hidden varaible aspx ..input type and call this method in pageload is itnot very easy)

thorugh

Posted by prathi Atluri Oct 12, 2007