javascript - 如何使用javascript或jquery设置listview中hiddenfield的值

标签 javascript jquery asp.net ajax telerik

我使用以下 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>
<小时/>

来自 Firebug:

<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>
<小时/>

我想用我的文本框所选值设置隐藏字段。

最佳答案

现在控件位于 ListView 中,您无法直接访问它。

我要做的是创建一个公共(public)变量,例如 theID,然后在 listview.itemcreated 事件中,使用 findcontrol 查找控件,然后将公共(public)变量的值设置为其 clientId,然后在页面中使用该公共(public)变量.

关于javascript - 如何使用javascript或jquery设置listview中hiddenfield的值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26448375/

相关文章:

javascript - Lightbox 可以工作,但上传到服务器时不工作

javascript - 找不到包裹在匿名函数中的递归函数调用

javascript - 按回车键时如何选择网格第一行?

jquery - jqGrid 在分组时对列进行排序考虑分组标题

javascript - 在图像加载时将图像从零放大到完整尺寸

javascript - 雅虎财经 API 历史报价

jquery - 表更新时,Tablesorter 不会重新应用过滤器?

asp.net - Linq to Entities 查询结果的基础类型是什么?

c# - 初始化属性时的问题

javascript - 将调整大小功能添加到 asp 文本框