This is a migrated thread and some comments may be shown as answers.

Dropdown fill in Edit form

1 Answer 65 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Thenmozhi
Top achievements
Rank 1
Thenmozhi asked on 29 Dec 2010, 09:51 AM
hi,

I have a rad grid with  edit for mas like below.
<EditFormSettings EditFormType="Template">
                  
                    <FormTemplate>

  <tr>
        <td style="width: 140px;">
            
        </td>
        <td>
            <asp:RadioButtonList ID="rbtntagtype" runat="server" AutoPostBack="true"  onselectedindexchanged="rbtntagtype_SelectedIndexChanged" >
            <asp:ListItem Text="Service" Value="Service" Selected="True"></asp:ListItem>
            <asp:ListItem Text="Doctor" Value="Doctor"></asp:ListItem>
            </asp:RadioButtonList>
        </td>
    </tr>
    <tr>
        <td style="width: 140px;">
             <asp:Label ID="Label2" runat="server" Text="Service Tags"></asp:Label>
        </td>
        <td>
            <asp:DropDownList ID="ddlservicetag" runat="server">
            </asp:DropDownList>
        </td>
    </tr>
</FormTemplate>
                </EditFormSettings>

I have a Radio button list.

Based on the radio button list selection have to load the values to drop down.

In code behind i written like below.

protected void rbtntagtype_SelectedIndexChanged(object sender, EventArgs e)
    {
        RadioButtonList rbtntag = (RadioButtonList)sender;

        GridEditableItem edititem = (sender as DropDownList).NamingContainer as GridEditableItem;
        DropDownList ddList = edititem.FindControl("ddlservicetag") as DropDownList;

        DataSet dl_loadservice = new DataSet();

        if (rbtntag.SelectedItem.Value == "Doctor")
        {
            dl_loadservice = objClass_RegisterDept.fn_getservicetags(true);
        }
        else
        {
            dl_loadservice = objClass_RegisterDept.fn_getservicetags(false);
        }
        ddList.DataSource = dl_loadservice;
        ddList.DataTextField = "tagname";
        ddList.DataValueField = "tagid";
        ddList.DataBind();
        ddList.Items.Insert(0, "Select");
    }

in selected index chnage itis saying
GridEditableItem edititem = (sender as DropDownList).NamingContainer as GridEditableItem;
is null..

can anyone suggest me how do i proceed with this..

1 Answer, 1 is accepted

Sort by
0
Thenmozhi
Top achievements
Rank 1
answered on 29 Dec 2010, 09:59 AM
I have modified my code behind function as like below

 protected void rbtntagtype_SelectedIndexChanged(object sender, EventArgs e)
    {
        RadioButtonList rbtntag = (RadioButtonList)sender;

        GridEditFormItem edititem = (GridEditFormItem)rbtntag.NamingContainer;   
        DropDownList ddList = edititem.FindControl("ddlservicetag") as DropDownList;

        DataSet dl_loadservice = new DataSet();

        if (rbtntag.SelectedItem.Value == "Doctor")
        {
            dl_loadservice = objClass_RegisterDept.fn_getservicetags(true);
        }
        else
        {
            dl_loadservice = objClass_RegisterDept.fn_getservicetags(false);
        }
        ddList.DataSource = dl_loadservice;
        ddList.DataTextField = "tagname";
        ddList.DataValueField = "tagid";
        ddList.DataBind();
        ddList.Items.Insert(0, "Select");
    }
now it started working..
Tags
Grid
Asked by
Thenmozhi
Top achievements
Rank 1
Answers by
Thenmozhi
Top achievements
Rank 1
Share this question
or