Harshal Kulkarni

Harshal Kulkarni

  • NA
  • 26
  • 9.5k

how to assign linkbutton name in gridview

Jan 24 2017 5:23 AM
I'm getting object reference error.. 
my code is :

protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
foreach (GridViewRow r in GridView1.Rows)
{
LinkButton lbl = (LinkButton)r.Cells[1].FindControl("LinkButton1");
//LinkButton lbl = (LinkButton)e.Row.FindControl("LinkButton1") as LinkButton; 
string str = r.Cells[0].Text;
string str1 = str.Substring(0, str.IndexOf("(")).Trim();
if (str1 == "Abnormal")
{
con.Open();
cmd = new OracleCommand("", con);
dr = cmd.ExecuteReader();
while (dr.Read())
{
lbl.Text = dr[0].ToString();
//r.Cells[1].Text = dr[0].ToString();
}
con.Close();
}
else if (str1 == "Sub-Normal")
{
con.Open();
cmd = new OracleCommand(" ", con);
dr = cmd.ExecuteReader();
while (dr.Read())
{
lbl.Text = dr[0].ToString(); 
//r.Cells[1].Text = dr[0].ToString();
}
con.Close();
}
else if (str1 == "Normal")
{
con.Open();
cmd = new OracleCommand("", con);
dr = cmd.ExecuteReader();
while (dr.Read())
{
lbl.Text = dr[0].ToString(); 
//r.Cells[1].Text = dr[0].ToString();
}
con.Close();
}
else if (str1 == "Critical")
{
con.Open();
cmd = new OracleCommand("", con);
dr = cmd.ExecuteReader();
while (dr.Read())
{
lbl.Text = dr[0].ToString(); 
//r.Cells[1].Text = dr[0].ToString();
}
con.Close();
}
else if (str1 == "Super Critical")
{
con.Open();
cmd = new OracleCommand("", con);
dr = cmd.ExecuteReader();
while (dr.Read())
{
lbl.Text = dr[0].ToString(); 
//r.Cells[1].Text = dr[0].ToString();
}
con.Close();
}
}
 
}
 
Thanks in advanced. 

Answers (3)