0

我正在使用 Telerik 网格,因为我必须在 javascript 中找到过滤控件及其值。请帮我。这是aspx的示例代码

<telerik:RadGrid ShowFooter="True" ID="grdQtmItemDetails" runat="server" GridLines="None"
    AllowPaging="false" AllowSorting="True" AutoGenerateColumns="False" Width="815px"
    PageSize="5" Height="430px" AllowFilteringByColumn="true" OnItemDataBound="grdQtmItemDetails_ItemDataBound"
    OnNeedDataSource="grdQtmItemDetails_NeedDataSource">
        <PagerStyle Mode="NextPrevAndNumeric"></PagerStyle>
        <MasterTableView GridLines="None" Width="250%">
             <Columns>
                  <telerik:GridTemplateColumn HeaderText="SLNO" UniqueName="SL_NO">
                       <ItemTemplate>
                            <%# Eval("SL_NO")%>
                        </ItemTemplate>
                        <FilterTemplate>
                            <telerik:RadTextBox ID="txtslno" runat="server" Enabled="False" Width="100%">
                            </telerik:RadTextBox>
                        </FilterTemplate>
                        <HeaderStyle Width="50px" />
                  </telerik:GridTemplateColumn>
                  <telerik:GridTemplateColumn HeaderText="Material Code" UniqueName="MTRL_CD">
                        <ItemTemplate>
                             <%# Eval("MTRL_CD")%>
                        </ItemTemplate>
                        <FilterTemplate>
                             <telerik:RadComboBox ID="cmbMaterialCodeTab2" runat="server" TabIndex="27" Width="100%"
                                     DropDownWidth="300px" EmptyMessage="--Select--" HighlightTemplatedItems="True"
                                     MarkFirstMatch="True">
                                  <HeaderTemplate>
                                       <table style="width: 250px">
                                            <tr>
                                                 <td style="width: 60px;">
                                                      Code
                                                 </td>
                                                 <td style="width: 170px;">
                                                      Description
                                                 </td>
                                            </tr>
                                       </table>
                                 </HeaderTemplate>
                                 <ItemTemplate>
                                      <table style="width: 250px">
                                          <tr>
                                              <td style="width: 60px;">
                                                  <%# DataBinder.Eval(Container.DataItem, "MTRL_CD")%>
                                              </td>
                                              <td style="width: 170px;">
                                                  <%# DataBinder.Eval(Container.DataItem, "MTRL_DESC")%>
                                              </td>
                                         </tr>
                                    </table>
                               </ItemTemplate>
                           </telerik:RadComboBox>
                           <sup>*</sup>
                      </FilterTemplate>
                 </telerik:GridTemplateColumn>
                 <telerik:GridTemplateColumn HeaderText="Materail Description" UniqueName="MTRL_DESC" >
                      <ItemTemplate>
                           <%# Eval("MTRL_DESC")%>
                      </ItemTemplate>
                      <FilterTemplate>
                           <telerik:RadTextBox ID="txtmtrldesctab2" runat="server" >
**<ClientEvents OnValueChanged="test" />**
                           </telerik:RadTextBox>
                      </FilterTemplate>
                      <HeaderStyle Width="150px" />
                 </telerik:GridTemplateColumn>
                 <telerik:GridTemplateColumn HeaderText="UOM" UniqueName="UOM_ID">
                      <ItemTemplate>
                            <%# Eval("UOM_ID")%>
                      </ItemTemplate>
                      <FilterTemplate>
                            <telerik:RadTextBox ID="txtUomIdtab2" runat="server" Width="100%" Enabled="false">
                            </telerik:RadTextBox><sup>*</sup>
                      </FilterTemplate>
                 </telerik:GridTemplateColumn>
            </Columns>
            <ExpandCollapseColumn Visible="False">
                 <HeaderStyle Width="19px"></HeaderStyle>
            </ExpandCollapseColumn>
            <CommandItemSettings ExportToPdfText="Export to PDF" />
            <RowIndicatorColumn Visible="False">
                 <HeaderStyle Width="20px" />
            </RowIndicatorColumn>
            <EditFormSettings>
                 <EditColumn FilterControlAltText="Filter EditCommandColumn column">
                 </EditColumn>
            </EditFormSettings>
       </MasterTableView>
       <ClientSettings AllowDragToGroup="True" AllowColumnsReorder="True">
           <Resizing AllowColumnResize="true" />
           <Scrolling AllowScroll="True" UseStaticHeaders="True" SaveScrollPosition="true">
           </Scrolling>
           <Selecting AllowRowSelect="false" />
       </ClientSettings>
       <FilterMenu EnableImageSprites="False">
       </FilterMenu>
 </telerik:RadGrid>

现在我该如何编写javascript函数

function test(sender,args)
{
//please write some code here to find filter items;
}

写一些东西来找到我的过滤器项目。提前致谢。

4

1 回答 1

0

请尝试下面的代码片段。

ASPX:

<asp:HiddenField ID="hidden1" runat="server" />

C#

protected void grdQtmItemDetails_ItemDataBound(object sender, Telerik.Web.UI.GridItemEventArgs e)
{
    if (e.Item is GridFilteringItem)
    {
        GridFilteringItem item = (GridFilteringItem)e.Item;
        TextBox txtslno = (TextBox)item.FindControl("txtslno");
        hidden1.Value = txtslno.ClientID.ToString();
    }
}

JS

function test(sender, args) {
            var hidden = document.getElementById("hidden1").value;
            var txtslno = document.getElementById(hidden);
            if (txtslno != null) {
                // Access Your TextBox here
            }
 }

注意:如果您得到隐藏变量的值为空,请尝试使用下面的代码片段。

 var hidden = $find("<%= hidden1.ClientID %>").val();
 var hidden = $('#<%= hidden1.ClientID %>').val();
于 2012-12-04T06:33:43.407 回答