Click here to Skip to main content
15,896,557 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,

I am suffering through a problem that my ddl is in not working as req in edit mode of gv. Suppose if i have a user info in gv and it shows Enabled as in label. Then i click on edit button of gv and ddl is taken to make the user enabled or disabled. By default is is picking the enabled field or selected index even if the user is disabled. Updation of gv is working fine. No other error is there, only the ddl is showing incorrect data. My Code is gvn below:
C#
protected void gv_All_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.DataRow &&
          (e.Row.RowState & DataControlRowState.Edit) == DataControlRowState.Edit)
        {
            string strEnabled = Convert.ToString(Session["enabled"]);
            DropDownList ddlenabled = (DropDownList)e.Row.FindControl("ddlEnabled");
            if (strEnabled!= "")
            {
                if (strEnabled== "Disabled")
                {
                    ddlenabled.SelectedIndex=2;
                }
                else
                {

                    ddlenabled.SelectedIndex = 1;
                }
            }
            else
            {
                ddlenabled.SelectedIndex = 0;
            }
        }
    }


and please forgive me for my short forms... I am in extreme hurry...
Please help ASAP...:(
Posted

1 solution

Hi,

as I can see in your code, you are trying to manipulate the value of a string "strEnabled" which stores Session["enabled"]. The value of "strEnabled" never changes on ddl selectedindexchanged.

Hence I would suggest you to work out on strEnabled strings value, or fetch the value of control ddlenabled in gv row.

Revert if you still have any queries.

Happy Coding :)
 
Share this answer
 
v2
Comments
Taresh Uppal 21-May-12 1:40am    
Hi sunny..somehow i solved it by myself.... and i did it by fetchin the value of label on editing of gv and than assigning the drop downs that value.
However a small bug is there. I have used many gvs and in some gvs its working fine and in sme gvs what it does that if yes or no is there and no is populated on editing and i update it to yes than next tym during edition i have two option yes and yes only... why is it happening ?
Sunny_Kumar_ 21-May-12 1:45am    
unable to imagine a clear picture from this little explanation " if yes or no is there and no is populated on editing and i update it to yes than next tym during edition i have two option yes and yes only". can you pls share a bit of code relating to this query... that would be very helpful getting a clear picture of the subject.
Taresh Uppal 21-May-12 1:46am    
Sure here it is ...

protected void gv_WorkOrder_Edit_RowEditing(object sender, GridViewEditEventArgs e)
{
int iClientId = Convert.ToInt32(Session["ClientID"]);

Label lblDataType = (Label)gv_WorkOrder_Edit.Rows[e.NewEditIndex].FindControl("lblDATATYPE");
Label lblComb = (Label)gv_WorkOrder_Edit.Rows[e.NewEditIndex].FindControl("lblCOMBI");
Label lblActive = (Label)gv_WorkOrder_Edit.Rows[e.NewEditIndex].FindControl("lblActive_Single");

gv_WorkOrder_Edit.EditIndex = e.NewEditIndex;
gv_work_edit_bind(iClientId);

DropDownList ddlData = ((DropDownList)(gv_WorkOrder_Edit.Rows[e.NewEditIndex].FindControl("ddlDataType")));
DropDownList ddlComb = ((DropDownList)(gv_WorkOrder_Edit.Rows[e.NewEditIndex].FindControl("ddlComb")));
DropDownList ddlActive = ((DropDownList)(gv_WorkOrder_Edit.Rows[e.NewEditIndex].FindControl("ddlActive_Single")));

ddlData.SelectedItem.Text = lblDataType.Text;
ddlComb.SelectedItem.Text = lblComb.Text;
ddlActive.SelectedItem.Text = lblActive.Text;


}
Taresh Uppal 21-May-12 1:49am    
so now once editing is done and if say ddlActive has updated to Yes than next time on editing if have only two option in that ddl YES and YES...and do remember that the ddls in my gvs, they have list items already in my design..only there value is dynamically highlighted.
Taresh Uppal 21-May-12 1:53am    
hey sunny thanx for your time...I solved it myself...Actually earlier I was trying to implement the logic using Gv_rowDataBound event. so i forgot to remove the event. Once i Did it its working fyn. Thanx for ur patience.
Have a great day//:)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900