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

Insert/update Server side...

1 Answer 77 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
S
Top achievements
Rank 1
S asked on 16 Dec 2011, 10:07 PM
Hi, 

I am very new to telerik...I have a data,which I displayed using radgrid and also I was able to get a pop-up when I click on edit link.

But in update and insert ..I need to add some code behind ...

i tried writing code behind by placing radbuttons and writing some code on Oncommand event..

But my textbox ID's which are used in Edit template are not accesible in this function.

Please advise if there any other way to handle this...Attached my sample page for better understanding...


Thanks a lot..

<telerik:RadGrid ID="SearchResult" runat="server" CellSpacing="0" height ="100%"
            GridLines="None" AllowPaging="True" AllowSorting="True" Skin="WebBlue" 
            OnNeedDataSource="RadGrid1_NeedDataSource"  DataSourceID="SearchDataSource" AllowAutomaticUpdates ="True"
             OnItemCommand="RadGrid1_ItemCommand"
              OnColumnCreated ="RadGrid1_ColumnCreated"
              OnSelectedIndexChanged ="RadGrig1_SelectedIndexChanged"
               Font-Names="Capital TT"  >
            <GroupingSettings CaseSensitive="False" />
            <ClientSettings>
                <Selecting AllowRowSelect="True" />
              
            </ClientSettings>
            <MasterTableView DataKeyNames="EID" CommandItemDisplay="TopAndBottom"  EditMode="PopUp">
                <RowIndicatorColumn FilterControlAltText="Filter RowIndicator column">
                </RowIndicatorColumn>
                <ExpandCollapseColumn FilterControlAltText="Filter ExpandColumn column">
                </ExpandCollapseColumn>
                <Columns>

                 <telerik:GridEditCommandColumn>
                </telerik:GridEditCommandColumn>
                 
                    
                </Columns>
                <CommandItemSettings ExportToPdfText="Export to PDF" />
                

                 <EditFormSettings InsertCaption="Add new item" CaptionFormatString="Edit EID: {0}"
                CaptionDataField="EID" EditFormType="Template" PopUpSettings-Modal="true">

                 <FormTemplate>
                    <table id="Table1" cellspacing="1" cellpadding="1" width="250" border="0">
                        <tr>
                            <td>
                            </td>
                            <td>
                            </td>
                        </tr>
                        <tr>
                            <td>
                                FirstName:
                            </td>
                            <td>
                                <asp:TextBox ID="TextBox10" Text='<%# Bind( "FirstName") %>' runat="server">
                                </asp:TextBox>
                            </td>
                        </tr>
                        <tr>
                            <td>
                                Last Name:
                            </td>
                            <td>
                                <asp:TextBox ID="TextBox11" Text='<%# Bind( "LastName") %>' runat="server">
                                </asp:TextBox>
                            </td>
                        </tr>
                        <tr>
                            <td>
                                EmploymentStatus:
                            </td>
                            <td>
                                <asp:TextBox ID="TextBox12" Text='<%# Bind( "EmploymentStatus") %>' runat="server">
                                </asp:TextBox>
                            </td>
                        </tr>
                        <tr>
                            <td colspan="2">
                                <hr />
                            </td>
                        </tr>
                        <tr>
                            <td>
                                EmployeeSubgroup:
                            </td>
                            <td>
                                <asp:TextBox ID="TextBox1" runat="server" Text='<%# Bind( "EmployeeSubgroup" ) %>'>
                                </asp:TextBox>
                            </td>
                        </tr>
                        
                    </table>
                    <table style="width: 100%">
                        <tr>
                            <td align="right" colspan="2">
                                <telerik:RadButton ID="Button1" Text='<%# (Container is GridEditFormInsertItem) ? "Insert" : "Update" %>'
                                 OnCommand="CommandBtn_Click"  runat="server" CommandName='<%# (Container is GridEditFormInsertItem) ? "PerformInsert" : "Update" %>'>
                                </telerik:RadButton>&nbsp;
                                <telerik:RadButton ID="Button2" Text="Cancel" runat="server" CausesValidation="False" CommandName="Cancel" OnClick="btncancel">
                                </telerik:RadButton>
                            </td>
                        </tr>
                    </table>
                </FormTemplate>
            </EditFormSettings>

               
               <HeaderStyle Font-Size="Smaller" Font-Names="Capital TT" Font-Bold="True" />

            </MasterTableView>
             <ClientSettings>
            <ClientEvents OnRowDblClick="RowDblClick" />
        </ClientSettings>
            <FilterMenu EnableImageSprites="False">
            </FilterMenu>
            <HeaderContextMenu CssClass="GridContextMenu GridContextMenu_Default">
            </HeaderContextMenu>
        </telerik:RadGrid>



.cs class.

protected void CommandBtn_Click(object sender, CommandEventArgs e)
    {


        if (e.CommandName == "Update")
        {
            
        }

        else if (e.CommandName == "PerformInsert")
        {
        }

1 Answer, 1 is accepted

Sort by
0
Accepted
Shinu
Top achievements
Rank 2
answered on 19 Dec 2011, 05:09 AM
Hello,

Try the following code.
C#:
protected void RadButton1_Click(object sender, EventArgs e)
{
 RadButton btn = (RadButton)sender;
 GridEditableItem item = (GridEditableItem)btn.NamingContainer;
 TextBox txt = (TextBox)item.FindControl("TextBox1");
}
       

-Shinu.
Tags
General Discussions
Asked by
S
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
Share this question
or