Reputation: 11393
This is the first time i use The RadGrid
<telerik:radgrid id="gv_about" runat="server" cssclass="RadGrid" allowpaging="True"
pagesize="20" allowsorting="True" autogeneratecolumns="False" showstatusbar="True"
allowautomaticdeletes="True" allowautomaticinserts="True" allowautomaticupdates="True"
datasourceid="ObjectDataSource1" onitemdeleted="gv_about_ItemDeleted" oniteminserted="gv_about_ItemInserted"
onitemupdated="gv_about_ItemUpdated" onitemcommand="gv_about_ItemCommand" onprerender="gv_about_PreRender">
<MasterTableView CommandItemDisplay="TopAndBottom" DataSourceID="ObjectDataSource1">
<commanditemsettings addnewrecordtext="اضافة" showrefreshbutton="False" />
<Columns>
<telerik:GridEditCommandColumn>
</telerik:GridEditCommandColumn>
<telerik:GridBoundColumn UniqueName="emp_num" HeaderText="رقم المحاضر" DataField="emp_num">
<HeaderStyle ForeColor="Silver" Width="25px"></HeaderStyle>
<ItemStyle ForeColor="Gray"></ItemStyle>
</telerik:GridBoundColumn>
<telerik:GridBoundColumn UniqueName="name" HeaderText="الاسم" DataField="name">
<HeaderStyle Width="220px"></HeaderStyle>
</telerik:GridBoundColumn>
<telerik:GridBoundColumn UniqueName="degree_name" HeaderText="الدرجة العلمية" DataField="degree_name">
</telerik:GridBoundColumn>
<telerik:GridBoundColumn UniqueName="college" HeaderText="الكلية والجامعة" DataField="college">
</telerik:GridBoundColumn>
<telerik:GridBoundColumn UniqueName="type" HeaderText="نوع المحاضر" DataField="type">
</telerik:GridBoundColumn>
<telerik:GridButtonColumn CommandName="Delete" Text="حذف" UniqueName="column">
</telerik:GridButtonColumn>
</Columns>
<EditFormSettings EditFormType="Template">
<EditColumn UniqueName="EditCommandColumn1" FilterControlAltText="Filter EditCommandColumn1 column"></EditColumn>
<FormTemplate>
<table id="Table2" cellspacing="2" cellpadding="1" width="100%" border="0" rules="none"
style="border-collapse: collapse;">
<tr class="EditFormHeader">
<td colspan="2" style="font-size: small">
<b>استمارة تعارف</b>
</td>
</tr>
<tr>
<td>
<table id="Table3" cellspacing="1" cellpadding="1" width="250" border="0" class="module">
<tr>
<td>
</td>
<td>
</td>
</tr>
<tr>
<td>
نوع المحاضر:
</td>
<td>
<div id="div_lect_type">
<asp:RadioButtonList ID="rbt_lect_type" runat="server" AppendDataBoundItems="true"
AutoPostBack="true" CausesValidation="false" RepeatDirection="Horizontal" OnSelectedIndexChanged="rbt_lect_type_SelectedIndexChanged">
<asp:ListItem Value="1" Text="معين" Selected="True"></asp:ListItem>
<asp:ListItem Value="2" Text="منتدب خارجي"></asp:ListItem>
<asp:ListItem Value="3" Text="جديد"></asp:ListItem>
</asp:RadioButtonList>
</div>
<div id="div_lect">
<asp:TextBox ID="txt_lect_in" runat="server" AutoPostBack="True" OnTextChanged="txt_lect_in_TextChanged"></asp:TextBox>
<asp:AutoCompleteExtender ID="txt_lect_in_AutoCompleteExtender" runat="server" DelimiterCharacters=""
Enabled="True" MinimumPrefixLength="4" ServiceMethod="Get_Emp_AutoComplete" ServicePath="~/LectIn.asmx"
TargetControlID="txt_lect_in" BehaviorID="ACE_txt_lect_in" CompletionListCssClass="autocomplete_completionListElement"
CompletionListHighlightedItemCssClass="autocomplete_highlightedListItem" CompletionListItemCssClass="autocomplete_listItem"
EnableCaching="False">
</asp:AutoCompleteExtender>
</div>
</td>
</tr>
<tr>
<td>
City:
</td>
<td>
<%-- <asp:TextBox ID="TextBox8" runat="server" Text='<%# Bind("City") %>' TabIndex="1">
</asp:TextBox>--%>
</td>
</tr>
<tr>
<td>
Region:
</td>
<td>
<%-- <asp:TextBox ID="TextBox9" runat="server" Text='<%# Bind("Region") %>' TabIndex="2">
</asp:TextBox>--%>
</td>
</tr>
<tr>
<td>
Home Phone:
</td>
<td>
<%-- <telerik:RadMaskedTextBox ID="HomePhoneBox" runat="server" SelectionOnFocus="SelectAll"
Text='<%# Bind("HomePhone") %>' PromptChar="_" Width="300px" Mask="(###) ###-####"
TabIndex="3">
</telerik:RadMaskedTextBox>--%>
</td>
</tr>
<tr>
<td>
Birth Date:
</td>
<td>
</td>
</tr>
<tr>
<td>
Title Of Courtesy
</td>
<td>
</td>
</tr>
</table>
</td>
<td>
<table id="Table1" cellspacing="1" cellpadding="1" width="250" border="0" class="module">
<tr>
<td>
Notes:
</td>
</tr>
<tr>
<td>
</td>
</tr>
<tr>
<td>
Address:
</td>
</tr>
<tr>
<td>
</td>
</tr>
</table>
</td>
</tr>
<tr>
<td align="right" colspan="2">
<asp:Button ID="btnUpdate" Text='<%# (Container is GridEditFormInsertItem) ? "Insert" : "Update" %>'
runat="server" CommandName='<%# (Container is GridEditFormInsertItem) ? "PerformInsert" : "Update" %>'>
</asp:Button>
<asp:Button ID="btnCancel" Text="Cancel" runat="server" CausesValidation="False"
CommandName="Cancel"></asp:Button>
</td>
</tr>
</table>
</FormTemplate>
</EditFormSettings>
</MasterTableView>
<ClientSettings>
<ClientEvents OnRowDblClick="RowDblClick"></ClientEvents>
</ClientSettings>
</telerik:radgrid>
The main problem is how to access controls in this grid from code behind and how to bind some of them or handling the events of them ??
For example how to access the txt_lect_in
from code behind ?
Upvotes: 0
Views: 1043
Reputation: 11154
Please try with the below code snippet.
protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e)
{
if (e.Item is GridEditFormItem && e.Item.IsInEditMode)
{
GridEditFormItem item = e.Item as GridEditFormItem;
TextBox txt_lect_in = item.FindControl("txt_lect_in") as TextBox;
//Access your textbox heer
}
}
//OR
protected void RadGrid1_ItemCreated(object sender, GridItemEventArgs e)
{
if (e.Item is GridEditFormItem && e.Item.IsInEditMode)
{
GridEditFormItem item = e.Item as GridEditFormItem;
TextBox txt_lect_in = item.FindControl("txt_lect_in") as TextBox;
//Access your textbox heer
}
}
Upvotes: 1