0

私はプロジェクトに取り組んでおり、グリッドビューにグリッドビューとラジオボタンがあり、ボタンをクリックして選択した行の値をデータベースに送信したいのですが、オブジェクト参照が設定されていないためエラーが発生していますオブジェクトのインスタンス。私のコードはボタンをクリックするだけの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());
    }
}   
4

2 に答える 2