Solved

get cell value from gridview with row index

Posted on 2008-11-02
3
3,887 Views
Last Modified: 2013-12-17
I am trying to get the specific cell value from my GridView in the RowDataBound method.

But I am getting an error.  Please help?
protected void gvDisposition_RowDataBound(object sender, GridViewrowEventArgs e)
{
   if (e.Row.RowType == DataControlRowType.DataRow)
   {
     HyperLink editLink = (HyperLink)e.Row.FindControl("DispositionView");
     editLink.Attributes["href"] = "#";
     int index = e.Row.RowIndex ;
     GridViewrow row = gvDisposition.SelectedRow[index]; //get error with index is Zero
     string cellvalue = row.Cells[6].Text;
   }
}

Open in new window

0
Comment
Question by:andy12279
3 Comments
 
LVL 13

Accepted Solution

by:
TechTiger007 earned 125 total points
ID: 22862355
Try this
     GridViewrow row = gvDisposition.Rows[index]; //get error with index is Zero

0
 
LVL 16

Expert Comment

by:Gyanendra Singh
ID: 22862443
see this is not correct method to get selected row .. because this method always call when your gridview bind to data ... this method is used only for when you append something to your grid ( ie. javascript) or set some value ...

its better try some different method .. like deleting, selection, Editing etc

giving you example on editing event

<asp:GridView ID="MyDataGrid" runat="server" AutoGenerateColumns="false" OnEditcommand="MyDataGrid_EditCommand">

and on codebehind file use this
public void MyDataGrid_EditCommand(object s, DataGridCommandEventArgs e)
{
    MyDataGrid.EditItemIndex = e.Item.ItemIndex;
    BindData(); // this method for rebind your grid
}
0
 
LVL 2

Author Comment

by:andy12279
ID: 22863921
Thanks guys.  Both of your answers helped solve my problem .
0

Featured Post

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
This Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.

776 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question