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

Access editform from client side

1 Answer 60 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Tina
Top achievements
Rank 1
Tina asked on 04 Apr 2012, 01:30 PM
How to access the dropdownlist value on client side in button click
  <EditFormSettings EditFormType="Template">
<FormTemplate>
                   
                        <asp:DropDownList ID="editDropDown" runat="server">
                            <asp:ListItem Text="Item1"></asp:ListItem>
                            <asp:ListItem Text="Item2"></asp:ListItem>
                            <asp:ListItem Text="Item3"></asp:ListItem>
                        </asp:DropDownList>
                        <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
                        <asp:Button ID="btn" Text="btn" runat="server" OnClientClick="ddlValue();" />
                    </FormTemplate>
                </EditFormSettings>

1 Answer, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 04 Apr 2012, 01:50 PM
Hello Tina,

You can access the dropdownlist in ItemCreated and pass the ClientID to access it from client side. Here is the sample code.
C#:
protected void RadGrid1_ItemCreated(object sender, GridItemEventArgs e)
{
 if ((e.Item is GridEditFormItem && e.Item.IsInEditMode))
 {
    GridEditFormItem editFormItem = (GridEditFormItem)e.Item;
    DropDownList ddl = (DropDownList)editFormItem.FindControl("editDropDown");
    RadGrid1.Controls.Add(new LiteralControl("<script type='text/javascript'>window['ddlvalue'] = '" + ddl.ClientID + "';</script>"));
 }
}
JS:
function ddlvalue()
{
 var ddl = document.getElementById(window['ddlvalue']);
 if (!ddl)
 {
   alert("no item is edited");
   return false;
 }
  else
 {
  alert("value is: " + ddl.value);
 }
}

Thanks,
Princy.
Tags
General Discussions
Asked by
Tina
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Share this question
or