如何在rad网格中访问(设置、获取或绑定)控件
本文关键字:获取 绑定 控件 设置 rad 网格 访问 | 更新日期: 2023-09-27 18:23:57
这是我第一次使用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>
主要问题是如何从代码背后访问这个网格中的控件,以及如何绑定其中的一些控件或处理其中的事件??
例如,如何从代码背后访问txt_lect_in
?
请尝试使用以下代码片段。
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
}
}