我正在做一个项目,我在gridview中有一个gridview和一个单选按钮,我想要的是,我想通过单击按钮将选定的行值发送到数据库,但由于对象引用未设置为对象的实例。因为我的代码是点击按钮的cs代码
protected void btn_selectgridview_Click(object sender, EventArgs e)
{
int k = 0;
//Checkther whether atleast one check box is selected or not
for (int i = 0; i <=gvrepair_details.Rows.Count-1; i++)
{
GridViewRow row = gvrepair_details.Rows[i];
RadioButton rb = (RadioButton)row.FindControl("CheckBox1");
if (rb.Checked == true)
{
k++;
}
}
if (k == 0)
{
Page.ClientScript.RegisterStartupScript(this.GetType(),Guid.NewGuid().ToString(), "<script language=JavaScript>alert('select the value in grid');</script>");
return;
}
for (int i = 0; i <=gvrepair_details.Rows.Count-1; i++)
{
string bookname = gvrepair_details.Rows[i].Cells[1].Text;
string categoryname = gvrepair_details.Rows[i].Cells[2].Text;
string subcategory =gvrepair_details.Rows[i].Cells[3].Text;
string shelf_no = gvrepair_details.Rows[i].Cells[4].Text;
string isbn = gvrepair_details.Rows[i].Cells[5].Text;
string edition = gvrepair_details.Rows[i].Cells[6].Text;
string status = gvrepair_details.Rows[i].Cells[7].Text;
GridViewRow row = gvrepair_details.Rows[i];
RadioButton rb = (RadioButton)row.FindControl("CheckBox1");
if (rb.Checked == true)
{
InsertData(bookname, categoryname, subcategory, shelf_no, isbn, edition, status);
}
}
}
void InsertData(String bookname, String categoryname, String subcategory,String shelf_no,String isbn,String edition,String status)
{
try
{
sql = "insert into library_repair(bookname, categoryname, subcategoryname, shelf_no, isbn, edition, status)values('" +bookname+ "','" +categoryname+ "','" +subcategory+ "','"+shelf_no+"','"+isbn+"','"+edition+"','"+status+"')";
ds = obj.openDataset(sql, Session["SCHOOLCODE"].ToString());
}
catch (Exception ex)
{
Response.Write(ex.ToString());
}
}