Open EditFormSettings template on asp Button click

5 posts, 0 answers
  1. Manish
    Manish avatar
    64 posts
    Member since:
    Jul 2011

    Posted 27 Mar 2014 Link to this post

    Hi,
    <telerik:RadGrid ID="rgCommnets" runat="server">
            <MasterTableView AutoGenerateColumns="false" CommandItemDisplay="None">
                <Columns>
                    <telerik:GridBoundColumn DataField="Comment_ID" HeaderText="" UniqueName="Comment_ID" Display="false"></telerik:GridBoundColumn>
                    <telerik:GridBoundColumn DataField="Attachment_ID" HeaderText="" UniqueName="Attachment_ID" Display="false"></telerik:GridBoundColumn>

                    <telerik:GridTemplateColumn HeaderText="Title">
                        <ItemTemplate>
                            <asp:Label ID="Title" runat="server" Text='<%#DataBinder.Eval(Container.DataItem,"Title") %>'></asp:Label>
                            <asp:LinkButton runat="server" Text='<%#DataBinder.Eval(Container.DataItem,"File_Name") %>' ID="lnkAttachment" OnClick="lnkAttachment_Click"></asp:LinkButton>
                        </ItemTemplate>
                    </telerik:GridTemplateColumn>
                    <telerik:GridBoundColumn DataField="Title" HeaderText="Title" UniqueName="Title"></telerik:GridBoundColumn>

                    <telerik:GridBoundColumn DataField="Status" HeaderText="Status" UniqueName="Status"></telerik:GridBoundColumn>
                </Columns>
                <EditFormSettings>
                    <FormTemplate >
                   <div class="divNarrativeComment">
                                <label>
                                    Comment Title:</label>
                                <asp:TextBox ID="textbox1" runat="server" Width="658px" Height="18px"></asp:TextBox>
                                <asp:TextBox ID="textbox2" runat="server" Width="754px" Height="50px" TextMode="MultiLine"
                                    CssClass="mbm"></asp:TextBox>
                                <label>
                                    Attachment:</label>
                                <br class="clearLeft" />
                                <label>
                                    For:</label>
                                <asp:RadioButtonList ID="RadioButtonList1" runat="server" RepeatDirection="Horizontal"
                                    CssClass="rblFor">
                                    <asp:ListItem>Contractor</asp:ListItem>
                                    <asp:ListItem>Internal</asp:ListItem>
                                </asp:RadioButtonList>
                                <br class="clearLeft" />
                                <label>
                                    Actionable item?</label><asp:CheckBox ID="CheckBox1" runat="server" Text="Yes" CssClass="rblFor chkAttachment" /><br
                                        class="clearLeft" />
                                <label>
                                    Choose role:</label><telerik:RadComboBox ID="RadComboBox2" runat="server" Skin="Metro"
                                        Width="300px" CssClass="left">
                                    </telerik:RadComboBox>
                                <asp:Button ID="Button2" runat="server" Text="Save" CssClass="buttons btnSearch right" />
                                <a class="lnkClear right">Discard</a><br class="clearLeft" />
                            </div>
                    </FormTemplate>
                </EditFormSettings>
            </MasterTableView>

        </telerik:RadGrid>


    In above code i have add <telerik:RadGrid ID="rgCommnets" runat="server">
            <MasterTableView AutoGenerateColumns="false" CommandItemDisplay="None">
                <Columns>
                    <telerik:GridBoundColumn DataField="Comment_ID" HeaderText="" UniqueName="Comment_ID" Display="false"></telerik:GridBoundColumn>
                    <telerik:GridBoundColumn DataField="Attachment_ID" HeaderText="" UniqueName="Attachment_ID" Display="false"></telerik:GridBoundColumn>

                    <telerik:GridTemplateColumn HeaderText="Title">
                        <ItemTemplate>
                            <asp:Label ID="Title" runat="server" Text='<%#DataBinder.Eval(Container.DataItem,"Title") %>'></asp:Label>
                            <asp:LinkButton runat="server" Text='<%#DataBinder.Eval(Container.DataItem,"File_Name") %>' ID="lnkAttachment" OnClick="lnkAttachment_Click"></asp:LinkButton>
                        </ItemTemplate>
                    </telerik:GridTemplateColumn>
                    <telerik:GridBoundColumn DataField="Title" HeaderText="Title" UniqueName="Title"></telerik:GridBoundColumn>

                    <telerik:GridBoundColumn DataField="Status" HeaderText="Status" UniqueName="Status"></telerik:GridBoundColumn>
                </Columns>
                <EditFormSettings>
                    <FormTemplate >
                   <div class="divNarrativeComment">
                                <label>
                                    Comment Title:</label>
                                <asp:TextBox ID="textbox1" runat="server" Width="658px" Height="18px"></asp:TextBox>
                                <asp:TextBox ID="textbox2" runat="server" Width="754px" Height="50px" TextMode="MultiLine"
                                    CssClass="mbm"></asp:TextBox>
                                <label>
                                    Attachment:</label>
                                <br class="clearLeft" />
                                <label>
                                    For:</label>
                                <asp:RadioButtonList ID="RadioButtonList1" runat="server" RepeatDirection="Horizontal"
                                    CssClass="rblFor">
                                    <asp:ListItem>Contractor</asp:ListItem>
                                    <asp:ListItem>Internal</asp:ListItem>
                                </asp:RadioButtonList>
                                <br class="clearLeft" />
                                <label>
                                    Actionable item?</label><asp:CheckBox ID="CheckBox1" runat="server" Text="Yes" CssClass="rblFor chkAttachment" /><br
                                        class="clearLeft" />
                                <label>
                                    Choose role:</label><telerik:RadComboBox ID="RadComboBox2" runat="server" Skin="Metro"
                                        Width="300px" CssClass="left">
                                    </telerik:RadComboBox>
                                <asp:Button ID="Button2" runat="server" Text="Save" CssClass="buttons btnSearch right" />
                                <a class="lnkClear right">Discard</a><br class="clearLeft" />
                            </div>
                    </FormTemplate>
                </EditFormSettings>
            </MasterTableView>

        </telerik:RadGrid>

    In above code i have add EditFormSettings for add and edit row and now i want to open it on asp button click.

    Thanks
    Manish
  2. Princy
    Princy avatar
    17421 posts
    Member since:
    Mar 2007

    Posted 27 Mar 2014 in reply to Manish Link to this post

    Hi Manish,

    I guess you want to have a asp edit button in a GridTemplateColumn and open the edit form on its click. Please try the following code snippet.

    ASPX:
    <telerik:GridTemplateColumn>
        <ItemTemplate>
            <asp:Button ID="Button1" runat="server" Text="Edit" CommandName="Edit" />
        </ItemTemplate>
    </telerik:GridTemplateColumn>
    . . . . .
    <EditFormSettings EditFormType="Template">
        <FormTemplate>
     . . . . .
        </FormTemplate>
    </EditFormSettings>

    Thanks,
    Princy
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Manish
    Manish avatar
    64 posts
    Member since:
    Jul 2011

    Posted 28 Mar 2014 in reply to Princy Link to this post

    Hi Princy,

    Thanks for your quick reply but yes it is possible with your solution and i have done that already but i need to use asp button outside of radgrid.
    Please check attachment.
  5. Princy
    Princy avatar
    17421 posts
    Member since:
    Mar 2007

    Posted 31 Mar 2014 in reply to Manish Link to this post

    Hi Manish,

    I'm not clear about your requirement. Simply setting an edit button outside grid wont let you have the RadGrid edit form, since it doesn't identify any row to be edited. Please take a look at the sample code snippet. I have set the selected rows to be in edit mode from a button outside grid.

    ASPX:
    <ClientSettings Selecting-AllowRowSelect="true">
    </ClientSettings>
     . . .
    <asp:Button ID="btnEdit" runat="server" Text="Edit" OnClick="btnEdit_Click" />

    C#:
    protected void btnEdit_Click(object sender, EventArgs e)
    {
        foreach (GridDataItem item in RadGrid1.SelectedItems)
        {
            item.Edit = true;
            RadGrid1.Rebind();
        }
    }

    Please elaborate your requirement if this doesn't help.

    Thanks,
    Princy
  6. Konstantin Dikov
    Admin
    Konstantin Dikov avatar
    1803 posts

    Posted 31 Mar 2014 Link to this post

    Hello Manish,

    You could use the client-side API of the grid and use the masterTableView fireCommand() method to initiate edit or insert from a button outside the grid. Detailed information on this is available at the following help article: Here is a simple example on how to get reference to the client-side API of the grid and initiate edit of a particular item or to initiate insertion:
    <telerik:RadCodeBlock runat="server">
        <script type="text/javascript">
            function editItem(index) {
                var grid = $find("<%=RadGrid1.ClientID%>");
                grid.get_masterTableView().fireCommand("Edit", index);
            }
     
            function initInsert(index) {
                var grid = $find("<%=RadGrid1.ClientID%>");
                grid.get_masterTableView().fireCommand("InitInsert", "");
            }
        </script>
    </telerik:RadCodeBlock>
     
    <telerik:RadGrid runat="server" ID="RadGrid1" OnNeedDataSource="RadGrid1_NeedDataSource">
    </telerik:RadGrid>
     
    <asp:Button runat="server" ID="Button1" Text="Edit item 1" OnClientClick="editItem(1); return false" />
    <asp:Button runat="server" ID="Button2" Text="Init insert" OnClientClick="initInsert(); return false" />

    Hope that helps.


    Regards,
    Konstantin Dikov
    Telerik
     

    Build cross-platform mobile apps using Visual Studio and .NET. Register for the online webinar on 03/27/2014, 11:00AM US ET.. Seats are limited.

     
Back to Top
UI for ASP.NET Ajax is Ready for VS 2017