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

Getting data out of edit template in RadGrid

1 Answer 140 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Derek
Top achievements
Rank 1
Derek asked on 04 Aug 2010, 07:43 PM
I've been searching on here for a little bit and haven't been able to find anything to something that seems like it should be very simple.

I have a RadGrid with an edit column. I use a template for the edit form which is just a standard html table with some labels/text boxes in it. When the user clicks the submit button I want to get at the text boxes that the user is currently modifying.

<telerik:RadGrid ID="rgdTemp" runat="server"
        AllowFilteringByColumn="True" AllowPaging="True" AllowSorting="True"
        AutoGenerateColumns="False" GridLines="None"
        onitemcommand="rgdTemp_ItemCommand"
        onneeddatasource="rgdTemp_NeedDataSource" >
        <MasterTableView>
            <Columns>
                <telerik:GridBoundColumn UniqueName="FirstName" DataField="FirstName" HeaderText="First Name" />
                <telerik:GridBoundColumn UniqueName="LastName" DataField="LastName" HeaderText="Last Name" />
                <telerik:GridEditCommandColumn EditText="Add Second Voucher" ButtonType="PushButton" />
            </Columns>
            <EditFormSettings EditFormType="Template">
                <FormTemplate>
                    <table>
                        <tr>
                            <td>
                                First Name:
                            </td>
                            <td>
                                <asp:TextBox ID="txtFirstName" runat="server" ReadOnly="true" Text='<%# Bind( "FirstName" ) %>'/>                    
                            </td>
                        </tr>
                        <tr>
                            <td>
                                Last Name:
                            </td>
                            <td>
                                <asp:TextBox ID="txtLastName" runat="server" ReadOnly="true" Text='<%# Bind( "LastName" ) %>'/>                  
                            </td>
                        </tr>
                        <tr>
                            <td>
                                R:
                            </td>
                            <td>
                                <asp:TextBox ID="txtR" runat="server" />
                            </td>
                        </tr>
                        <tr>
                            <td>
                                P:
                            </td>
                            <td>
                                <asp:TextBox ID="txtP" runat="server" Text="0" />
                            </td>
                        </tr>
                        <tr>
                            <td>
                                <asp:Button ID="btnSubmit" runat="server" Text='<%# "Insert" %>'
                                        runat="server" CommandName='<%# "PerformInsert" %>'>
                                    </asp:Button>
                            </td>
                            <td>
                                <asp:Button ID="btnCancel" runat="server" Text="Cancel" OnClick="btnCancel_Click" />
                            </td>
                        </tr>
                    </table>
                </FormTemplate>
            </EditFormSettings>
            <RowIndicatorColumn>
            <HeaderStyle Width="20px"></HeaderStyle>
            </RowIndicatorColumn>
 
            <ExpandCollapseColumn>
            <HeaderStyle Width="20px"></HeaderStyle>
            </ExpandCollapseColumn>
        </MasterTableView>
    </telerik:RadGrid>


The insert button really could just be a button that points to the code behind normally, just was something I was playing with.

Thanks

1 Answer, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 05 Aug 2010, 06:55 AM
Hello Derek,

Try the following code snippet in ItemCommand event to get the TextBox and its value when the user clicks sumbit button.

C#:
protected void rgdTemp_ItemCommand(object source, GridCommandEventArgs e)
   {
       if (e.CommandName == "PerformInsert")
       {
           GridEditFormItem editItem = (GridEditFormItem)(e.Item as GridDataItem).EditFormItem;
           TextBox txtFirstName = (TextBox)editItem.FindControl("txtFirstName"); //access TextBox
           string firstName = txtFirstName.Text;//get the value in TextBox
       }
   }

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