Gopal Ji  Singh

Gopal Ji Singh

  • NA
  • 39
  • 31.8k

Getting error on row command of GridView

Sep 28 2013 10:46 AM
Hello every one
i m getting an error(Input string was not in a correct format.) on click of detail button please help me to resolve this problem.

my code is

 protected void grdexam_RowCommand(object sender, GridViewCommandEventArgs e)
    {
        if (e.CommandName == "dtls") 
        {
            Button btn = (Button)e.CommandSource;
            var index =Convert.ToInt32(btn.CommandArgument.ToString());
            GridViewRow row = grdexam.Rows[index];
            Label l1 = (Label)row.FindControl("Label1");
            SqlCommand cmd = new SqlCommand("select * from ExamMaster where groupid='" + Session["grpid"] + "' and papercode='" + l1 + "'", con);
            SqlDataAdapter adp = new SqlDataAdapter();
            DataTable dt = new DataTable();
            adp.Fill(dt);
            if (dt.Rows.Count > 0)
            {
                GridView1.DataSource = dt;
                GridView1.DataBind();
            }
            else 
            {
                Response.Write("wromg");
            }
        }
    }


please help me
thanks in advance 

Answers (2)