0

actually I have bounded a dropdownlist in gridview in edit mode, but the problem is that whenever i try to select another value from dropdownlist, it auto select the first value.

I also used !IsPostBack property on page_load event but still it is not selecting the another items.

 protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
    if (e.Row.RowType == DataControlRowType.DataRow)
    {
        if ((e.Row.RowState & DataControlRowState.Edit) > 0)
        {

            DropDownList ddlCost_Code = DropDownList)e.Row.FindControl("ddlCost_Code");

            BAL bl = new BAL();
            DataTable dt_for_CostCode = null;

            dt_for_CostCode = bl.Select_Cost_Code();
            if (dt_for_CostCode.Rows.Count > 0)
            {
                ddlCost_Code.DataSource = dt_for_CostCode;
                ddlCost_Code.DataTextField = "Cost_Code";
                ddlCost_Code.DataValueField = "Proposalno";
                ddlCost_Code.DataBind();
            }

}


  if (!IsPostBack)
    {


        try
        {

            Log_Booked_Info_Through_Booking_Table();


        }
        catch (Exception ex)
        {
            WebMsgBox.Show(ex.Message);
        }
    }

}
Gaurav
  • 557
  • 4
  • 11
  • 28

2 Answers2

0

Firstly, this will be more efficent.

if (e.Row.RowState == DataControlRowState.Edit)
{
     // your code here
}

Secondly, check the AutoPostBack property of DropDown inside your gridview. What is it set to. It should be false in your case, unless you have some logic set on the onselectedindexchanged event of dropdown.

Praveen Nambiar
  • 4,852
  • 1
  • 22
  • 31
  • your code didn't give the solution. I need to make AutoPostBack property True because I need to do something on onselectedindexchanged event. – Gaurav Mar 04 '13 at 08:46
  • sorry guys Actually I was forget to remove the page prerender event, which i write for some test. – Gaurav Mar 04 '13 at 11:00
0

Try this:

ddlCost_Code.SelectedIndex = 0;
Mr_Green
  • 40,727
  • 45
  • 159
  • 271
punter
  • 460
  • 1
  • 6
  • 22