none
dropdownlist is inside the gridview RRS feed

  • Question

  • ((DropDownList)GridView1.Rows[i].Cells[0].Controls[1]).SelectedValue

     

    hi, i m using above code to save the value of selected dropdownlist in grid view.

    if i changed a value of dropdownlist means the page gets loaded and after the data is stored. wt is the prob. pls help. when i click a update button "the data to be stored in db."

    in dropdownlist have a values of "PRESENT","ABSENT","LEAVE"

    if i select a PRESENT value and after i clicked the update button to store value in db. bt it is stored in db.  

    if i select a ABSENT value and after i clicked the update button to store value in db. bt it is NOT stored in db. 

    if i select a LEAVE  value and after i clicked the update button to store value in db. bt it is NOT stored in db. 

    protected void Button1_Click(object sender, EventArgs e)
        {

    if (IsPostBack)
            {
                for (int i = 0; i < GridView1.Rows.Count; i++)
                {
                    b = new SqlCommand("insert into attendance (stcode, stname, status, sex) values ('" + GridView1.Rows[i].Cells[1].Text + "','" + GridView1.Rows[i].Cells[2].Text + "','" + ((DropDownList)GridView1.Rows[i].Cells[0].Controls[1]).SelectedValue + "','" + GridView1.Rows[i].Cells[3].Text + "')", a);
                    a.Open();
                    b.ExecuteNonQuery();
                    a.Close();
                    Label7.Visible = true;
                    Label7.Text = "Updated";
                }
            }

    }


    Nithiyanantham
    • Edited by Nithiyanantham Friday, September 30, 2011 8:58 AM
    • Moved by Andreas Johansson Friday, September 30, 2011 9:18 AM ASP.NET (From:.NET Base Class Library)
    Friday, September 30, 2011 8:57 AM

All replies