Reputation: 39
I want to get the cell value from a grid view.
I am using the following code but it produces an error.
cmd.Parameters.Add("@ProjectCode", SqlDbType.VarChar).Value = ((GridView)TeamMemberGrid.Rows[e.RowIndex].Cells[1].Controls[0]).ToString();
@ProjectCode
is one of the fields in the grid view.
Upvotes: 0
Views: 1962
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
Reputation: 10620
I think its:
cmd.Parameters.Add("@ProjectCode", SqlDbType.VarChar).Value = ((GridView)TeamMemberGrid.Rows[e.RowIndex].Cells[1].Controls[0]).Text;
Upvotes: 0