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

Want to add LinkButton inside an edit form

1 Answer 41 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Kathy
Top achievements
Rank 1
Kathy asked on 19 Sep 2010, 09:47 PM
I'm trying to use the standard edit form for a particular grid.  One of the columns in the edit form is a radcombobox.  What I want to do is to find the combo box and place a linkbutton next to it which will say something like "add new site".  When the click the linkbutton, I'll show a small window which will basically take just a text value.  When they save this info, it will make a new site, and the new site's id and name will show up in the combobox.  Can anyone help me?  Thanks.

1 Answer, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 1
answered on 20 Sep 2010, 02:18 PM
Hello Kathy,

Here is one sample application to achieve this scenario. I added the LinkButton in EditItemTemplate of TemplateColumn with RadComboBox. Then attach 'OnClientClick' event to the button inside RadWindow, and invoke ajaxRequest from the event handler. Now in the AjaxManager_AjaxRequest server event, get the corresponding RadComboBox in editform and update it.

ASPX:
<telerik:RadAjaxManager ID="RadAjaxManager1" runat="server" OnAjaxRequest="RadAjaxManager1_AjaxRequest">
    <AjaxSettings>
        <telerik:AjaxSetting AjaxControlID="RadAjaxManager1">
            <UpdatedControls>
                <telerik:AjaxUpdatedControl ControlID="RadGrid1" />
            </UpdatedControls>
        </telerik:AjaxSetting>
    </AjaxSettings>
</telerik:RadAjaxManager>
<telerik:RadWindow ID="RadWindow1" runat="server">
    <ContentTemplate>
        <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
        <asp:Button ID="Button1" runat="server" Text="Save" OnClientClick="OnButtonClick();return false;" />
    </ContentTemplate>
</telerik:RadWindow>
<telerik:RadGrid ID="RadGrid1" . . . .>
       . . . . . . . . . . . .
        <Columns>
            <telerik:GridTemplateColumn>
                <EditItemTemplate>
                    <telerik:RadComboBox ID="RadComboBox1" runat="server">
                    </telerik:RadComboBox>
                         <asp:LinkButton ID="LinkButton1" runat="server" OnClientClick="OnLinkButtonClick();">add new site</asp:LinkButton>
                </EditItemTemplate>
            </telerik:GridTemplateColumn>
        </Columns>
       . . . . . . . . . . . . . . . .
</telerik:RadGrid>



C#:

  
protected void RadAjaxManager1_AjaxRequest(object sender, AjaxRequestEventArgs e)
   {
       GridEditFormItem editItem = (GridEditFormItem)RadGrid1.MasterTableView.GetItems(GridItemType.EditFormItem)[Convert.ToInt32(RadGrid1.EditIndexes[0])];
       RadComboBox combo = (RadComboBox)editItem.FindControl("RadComboBox1");
       RadComboBoxItem item = new RadComboBoxItem(TextBox1.Text);
       combo.Items.Add(item);
    }

Java Script:
<script type="text/javascript">
    function OnLinkButtonClick() {
        var oWnd = $find("RadWindow1");
        oWnd.show();
        return false;
    }
    function OnButtonClick() {
        $find("<%=RadAjaxManager1.ClientID%>").ajaxRequest();
        var oWnd = $find("RadWindow1");
        oWnd.hide();
    }
</script>

Thanks,
Princy.
Tags
Grid
Asked by
Kathy
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 1
Share this question
or