Solved

get cell value from gridview with row index

Posted on 2008-11-02
3
3,883 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
Comment Utility
Try this
     GridViewrow row = gvDisposition.Rows[index]; //get error with index is Zero

0
 
LVL 16

Expert Comment

by:Gyanendra Singh
Comment Utility
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
Comment Utility
Thanks guys.  Both of your answers helped solve my problem .
0

Featured Post

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

Suggested Solutions

Many of us here at EE write code. Many of us write exceptional code; just as many of us write exception-prone code. As we all should know, exceptions are a mechanism for handling errors which are typically out of our control. From database errors, t…
More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

743 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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now