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.
From stackoverflow
-
TableCell
has aText
property.thiru : how to get grid view cell value -
I think its:
cmd.Parameters.Add("@ProjectCode", SqlDbType.VarChar).Value = ((GridView)TeamMemberGrid.Rows[e.RowIndex].Cells[1].Controls[0]).Text;
thiru : this only produce error question and ur answer are samethiru : this is also produce errorBenB : I guess the next question would therefore be... What is the error produced?! -
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.
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.