I am binding data from SQL table in gridview. I want to change one column(command field) value not header at runtime. I am using following code but it change header also.
HTML code:
server side code:
protected void grddetails_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow || e.Row.RowType == DataControlRowType.Header)
{
int len = ds.Tables[0].Rows.Count;
for (int i = 0; i < len; i++)
{
int id = Convert.ToInt32(ds.Tables[0].Rows[i].ItemArray[0]);
// check ID exists or not
com = new SqlCommand("SELECT 1 FROM Table WHERE id=" + id + "", con);
con.Open();
drd = com.ExecuteReader();
if (drd.Read())
e.Row.Cells[4].Text="Apply";
else
e.Row.Cells[4].Text="not Apply";
con.Close();
}
}
Please help me
Thanks in advance

Shen Hengbin94 reputationPosted Jul 22, 2012, 12:15 AM EDT
Shen Hengbin94 reputationPosted Jul 20, 2012, 1:00 AM EDT
if (e.Row.RowType == DataControlRowType.DataRow || e.Row.RowType == DataControlRowType.Header)
To
if (e.Row.RowType == DataControlRowType.DataRow)
DataControlRowType.Header is the header row.
Pankaj Singh92 reputationPosted Jul 20, 2012, 9:24 AM EDT
Shen Hengbin94 reputationPosted Jul 21, 2012, 2:06 AM EDT
if (e.Row.RowType == DataControlRowType.DataRow)
{
DataRow row = ((DataRowView)e.Row.DataItem).Row;
int id = Convert.ToInt32(row.ItemArray[0]);
com = new SqlCommand("SELECT 1 FROM Table WHERE id=" + id + "", con);
con.Open();
drd = com.ExecuteReader();
if (drd.Read())
e.Row.Cells[4].Text="Apply";
else
e.Row.Cells[4].Text="not Apply";
con.Close();
}
Pankaj Singh92 reputationPosted Jul 21, 2012, 5:24 PM EDT
Pankaj Singh92 reputationPosted Jul 22, 2012, 9:21 AM EDT