Reputation: 5249
How can I access a value in a GridView, in this case i have a target_date
in there and would like to get that value and convert it to string. Here is what I have:
foreach (GridViewRow gr in GridView1.Rows)
{
CheckBox cb = (CheckBox)gr.FindControl("chkItem");
if (cb.Checked)
{
string strTargetDate = "???"; // TODO
}
}
Upvotes: 0
Views: 403
Reputation: 1885
The must be something like GridView1.Rows[(int)rowIndex].Cells[(int)ColIndex].Value; or GridView1.Rows[(int)rowIndex].Cells[(string)ColName].Value;
Upvotes: 0
Reputation: 10824
use this code :
foreach (GridViewRow gr in GridView1.Rows)
{
var cells = gr.Cells;
CheckBox cb = (CheckBox)gr.FindControl("chkItem");
if (cb.Checked)
{
string strTargetDate = cells[0].Text;
}
}
Upvotes: 2