我使用以下javascript通过autocompleteextender获取文本框的值。
<script type="text/javascript">
function txt_lect_in_AutoCompleteExtender_itemSelected(sender, e)
{
var hdEmpId = $get('<%= hf_emp_num.ClientID %>');
hdEmpId.value = e.get_value();
}
</script>
但是当我将文本框放入listview时,我无法再访问控件了。
<telerik:radlistview id="RadListView1" runat="server" itemplaceholderid="EmployeesContainer"
cssclass="formTable cr_center" groupitemcount="2">
<LayoutTemplate>
<fieldset >
<legend> <asp:Label ID="lblTitle" runat="server" Font-Bold="True" Font-Size="16pt" Height="29px"
Font-Names="Times New Roman (Arabic)" ForeColor="#CC6634" Text=" المحاضرون الذين يقومون بتدريس دورة:"></asp:Label><asp:Label
ID="lbl_course_name" runat="server" Font-Size="16pt" Height="29px" Font-Names="Times New Roman (Arabic)"
ForeColor="#000" Text='<%#Session["course_name"]%>'></asp:Label><br /></legend>
<asp:Panel ID="DataGroupPlaceHolder2" runat="server">
</asp:Panel>
</fieldset>
</LayoutTemplate>
<ItemTemplate>
<fieldset style="float: right; width: 430px;">
<table cellpadding="0" cellspacing="0" class="cr_subtable">
<tr>
<td>المحاضرة:
<%#Eval("session")%>
</td>
<td>
<asp:TextBox ID="txt_lect_in" runat="server" AutoPostBack="True" Width="300px"
Text = '<%#Eval("name_id")%>' 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="~/LectAbout.asmx"
TargetControlID="txt_lect_in" BehaviorID="ACE_txt_lect_in" CompletionListCssClass="autocomplete_completionListElement"
CompletionListHighlightedItemCssClass="autocomplete_highlightedListItem" CompletionListItemCssClass="autocomplete_listItem"
EnableCaching="False"
FirstRowSelected="true">
</asp:AutoCompleteExtender>
<asp:HiddenField ID="hf_emp_num" runat="server" Value ='<%#Eval("id")%>'></asp:HiddenField>
</td>
</tr>
</table>
</fieldset>
</ItemTemplate>
<datagroups>
<telerik:ListViewDataGroup GroupField="lect_date_dis" DataGroupPlaceholderID="DataGroupPlaceHolder2"
SortOrder="Ascending">
<DataGroupTemplate>
<asp:Panel runat="server" ID="Panel3" CssClass="dataGroup" GroupingText= '<%# (DateTime.Parse((Container as RadListViewDataGroupItem).DataGroupKey.ToString())).Date.ToString("MM-dd-yyyy")%>'>
<asp:PlaceHolder ID="EmployeesContainer" runat="server"></asp:PlaceHolder>
</asp:Panel>
</DataGroupTemplate>
</telerik:ListViewDataGroup>
</datagroups>
<GroupSeparatorTemplate>
<div style="clear: both">
</div>
<hr/>
</GroupSeparatorTemplate>
</telerik:radlistview>
来自萤火虫:
<div id="ctl00_ContentPlaceHolder1_RadListView1_ctrl0_Panel3" class="dataGroup">
<div style="clear: both"> </div>
<hr>
<div id="ctl00_ContentPlaceHolder1_RadListView1_ctrl4_Panel3" class="dataGroup">
<fieldset>
<legend> 01-28-2011 </legend>
<fieldset style="float: right; width: 430px;">
<fieldset style="float: right; width: 430px;">
<table class="cr_subtable" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td>المحاضرة: 4 </td>
<td>
<input id="ctl00_ContentPlaceHolder1_RadListView1_ctrl8_ctrl10_txt_lect_in" type="text" style="width:300px;" onkeypress="if (WebForm_TextBoxKeyHandler(event) == false) return false;" onchange="javascript:setTimeout('__doPostBack(\'ctl00$ContentPlaceHolder1$RadListView1$ctrl8$ctrl10$txt_lect_in\',\'\')', 0)" name="ctl00$ContentPlaceHolder1$RadListView1$ctrl8$ctrl10$txt_lect_in" autocomplete="off">
<input id="ctl00_ContentPlaceHolder1_RadListView1_ctrl8_ctrl10_hf_emp_num" type="hidden" name="ctl00$ContentPlaceHolder1$RadListView1$ctrl8$ctrl10$hf_emp_num">
</td>
</tr>
</tbody>
我想设置隐藏字段,其值为我的文本框选择值。
答案 0 :(得分:2)
现在控件位于列表视图中,您无法直接访问它。
我要做的是创建一个公共变量说theID,然后在listview.itemcreated事件中,使用findcontrol查找控件,然后将公共变量的值设置为其clientId,然后在页面中使用该公共变量
答案 1 :(得分:1)
由于你有很多实例(每个数据行一个),所以在你的元素上放一些CSS类,然后通过jQuery获取它们。 domElement.control属性将为您提供IScriptControl引用
答案 2 :(得分:0)
1)添加到TextBox
<asp:TextBox id = "txt_lect_in" onkeyup = "SetContextKey()" ></asp:Textbox>
2)在AutoCompleteExtender中添加:
UseContextKey = "true"
3)jquery
function SetContextKey() {
$find('<%=txt_lect_in_AutoCompleteExtender.ClientID%>').set_contextKey($get("<%=hf_emp_num.ClientID %>").value);
4) In Webservice Method :
public static List<string> Get_Emp_AutoComplete(string prefixText,int count, string contextKey)
Hope it helps,if something else please ask.