0

I want to get the cell value from a grid view.

I am using the following code but it produces an error.

Code:

cmd.Parameters.Add("@ProjectCode", SqlDbType.VarChar).Value = ((GridView)TeamMemberGrid.Rows[e.RowIndex].Cells[1].Controls[0]).ToString();

Note:

@ProjectCode is one of the fields in the grid view.

2
  • 1. Which programming language? 2. what "grid view"? Google returns 10 million results for "grid view". 3. Put the exact error message in your question. Commented Mar 11, 2009 at 11:27
  • 1. ASP.NET with c# 2 error is " Object reference not set to an instance of an object". Commented Mar 11, 2009 at 11:31

3 Answers 3

1

As Leppie has already stated, the TableCell object exposes a Text property which will give you access to the text contents of a TableCell.

What you need to understand is that the TeamMemberGrid.Rows[e.RowIndex].Cells[1] statement returns a TableCell object referencing the specified TableCell in your GridView.

So your statement becomes :

cmd.Parameters.Add("@ProjectCode", SqlDbType.VarChar).Value = TeamMemberGrid.Rows[e.RowIndex].Cells[1].Text;

Finally, the reason for the cast seems unclear in your statement so I removed that.

Sign up to request clarification or add additional context in comments.

Comments

0

TableCell has a Text property.

1 Comment

how to get grid view cell value
0

I think its:

cmd.Parameters.Add("@ProjectCode", SqlDbType.VarChar).Value = ((GridView)TeamMemberGrid.Rows[e.RowIndex].Cells[1].Controls[0]).Text;

1 Comment

I guess the next question would therefore be... What is the error produced?!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.