Solved

get cell value from gridview with row index

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my asp.net applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
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…
This tutorial gives a high-level tour of the interface of Marketo (a marketing automation tool to help businesses track and engage prospective customers and drive them to purchase). You will see the main areas including Marketing Activities, Design …
As a trusted technology advisor to your customers you are likely getting the daily question of, ‘should I put this in the cloud?’ As customer demands for cloud services increases, companies will see a shift from traditional buying patterns to new…

863 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

22 Experts available now in Live!

Get 1:1 Help Now