thiru
thiru

Reputation: 39

problem in getting cell value from grid view

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.

Upvotes: 0

Views: 1962

Answers (3)

Cerebrus
Cerebrus

Reputation: 25775

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.

Upvotes: 1

BenB
BenB

Reputation: 10620

I think its:

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

Upvotes: 0

leppie
leppie

Reputation: 117220

TableCell has a Text property.

Upvotes: 0

Related Questions