2
Answers

Getting error on row command of GridView

Gopal Ji  Singh

Gopal Ji Singh

11y
1.1k
1
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)