?
Solved

get cell value from gridview with row index

Posted on 2008-11-02
3
Medium Priority
?
3,903 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 13

Accepted Solution

by:
TechTiger007 earned 500 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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

User art_snob (http://www.experts-exchange.com/M_6114203.html) encountered strange behavior of Android Web browser on his Mobile Web site. It took a while to find the true cause. It happens so, that the Android Web browser (at least up to OS ver. 2.…
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…
In this video we outline the Physical Segments view of NetCrunch network monitor. By following this brief how-to video, you will be able to learn how NetCrunch visualizes your network, how granular is the information collected, as well as where to f…
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…
Suggested Courses

764 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