Solved

get cell value from gridview with row index

Posted on 2008-11-02
3
3,893 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 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

More Than Just A Video Library

Train for your certification. Learn the latest DevOps tools. Grow your skillset to do better work.

At Linux Academy, we release new training modules every week so you'll always be up to date on the latest tech.

Question has a verified solution.

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

Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
Come and listen to Percona CEO Peter Zaitsev discuss what’s new in Percona open source software, including Percona Server for MySQL (https://www.percona.com/software/mysql-database/percona-server) and MongoDB (https://www.percona.com/software/mongo-…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …

691 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