Thursday, 1 May 2014

Keeping item selected in dropdownlist when go to edit mode in gridview

No comments
            Button bt1 = (Button)sender;
            GridViewRow gr = (GridViewRow)bt1.NamingContainer;
            Label l1 = (Label)GridView1.Rows[gr.RowIndex].FindControl("Label1");
            Label l2 = (Label)GridView1.Rows[gr.RowIndex].FindControl("Label2");
            int index = gr.RowIndex;
            GridView1.EditIndex = index;
            GridView1.DataSource = bl.select_ALL_product();
            GridView1.DataBind();        
            DropDownList dl1 = (DropDownList)GridView1.Rows[gr.RowIndex].FindControl("dropcat");
            DropDownList dl2 = (DropDownList)GridView1.Rows[gr.RowIndex].FindControl("droptype");
            dl1.DataSource = bl1.select_cat();
            dl1.DataBind();
            dl1.SelectedItem.Text = l1.Text;         
            dl2.DataSource = bl1.select_type();
            dl2.DataBind();
            dl2.SelectedItem.Text = l2.Text;