2017-07-20 1 views
2

私は企業データベースにアクセスして操作できるWebサイトの作成を私に任せた会社のインターンです。これにより、共同作業者は、クライアントが使用しているコードを簡単に調べることができます。次の問題は、他の開発者と私を困らせました。JQuery BoundFieldを使用すると特定のGridview列を検索します

現在、jQueryの検索は、ボタンや「すべて」ボタンがクリックされていないときに機能し、テーブル全体を検索します。他のボタンはまだ検索しません。ボタンを認識するので、if/else ifステートメントに入りますが、ボタンの名前/クラスは認識されません。

GridViewsは、ドロップダウンリストから名前を選択し、各列にget/setメソッドを使用した後、GrdiView.DataSourceおよびDataBind()を使用してデータをバインドします。そのため、私はBoundFieldをTemplateFieldではなくDataFieldプロパティで使用していました。

質問:BoundFieldに名前/クラス/値を割り当てて、jQueryが列セルを見つける方法はありますか?または、TemplateFieldを動作させる方法はありますか?

$(document).on("keyup", function() 
{ 
    SearchGrid('<%=txtSearchBox.ClientID%>', '<%=grdIniData1.ClientID%>', 
    '<%=grdIniData2.ClientID%>'); 

    function SearchGrid(txtSearch, grd1, grd2) 
    {   
     if ($("input:radio[name=Section]").is(":checked")) 
     { 
     //Tried adding a CSS class to BoundField 'Section' and calling 
     $('.Section').each(function (i) 
     { 
      alert("hello"); 
      $("Section").quicksearch("[id*=grdList] tr:not(:has(th))", 
      { 
       'testQuery': function (query, txt, row) 
       { 
        return $(row).children(":eq(" + i")").text().toLowerCase(). 
        indexOf(query[0].toLowerCase()) != -1; 
       } 
      }); 
      }); 
     } 

    else if ($("input:radio[name=Name]").is(":checked")) 
    { 
     //For name and IniValue, tried accessing by BoundField name 
     //Unsure how to name BoundField so jQuery can access 
     $('#name').each(function() 
     { 
      if ($("Name").find('td').eq(1).text() != "") 
      { 
       $(this).index(); 
      } 
     }); 
     } 
     else if ($("input:radio[name=IniValue]").is(":checked")) 
     { 
     var searchKey = $("[id *=" + txtSearch + " ]").val().toLowerCase(); 
     $("#grd1 tr td:nth-child(2)").each(function() 
     { 
      var cellText = $(("input:radio[name=IniValue]"). 
      is(":checked")).text().toLowerCase(); 
      if (cellText.indexOf(searchKey) >= 0) 
      { 
       $("[id *=" + grd1 + " ]").parent().show(); 
      } 
      else 
      { 
       $("[id *=" + grd1 + " ]").parent().hide(); 
      } 
     }); 
     } 
     else 
     { 
     //Code is functional after this point 
     } 

<asp:GridView ID="grdIniData2" runat="server" AllowSorting="True" AutoGenereateColumns="false" AutoSizeColumnsMode="AllCellsExceptHeader" BackColor="White" BorderColor="#999999" BorderStyle="None" BorderWidth="1px" CellPadding="0" GridLines="Vertical" OnRowDataBound="grdIniData2_RowDataBound" OnSelectedIndexChanged="ddlClientList2_SelectedIndexChanged" OnSorting="grdIniData2_Sort" Font-Bold="True" Font-Names="Sylfaen" Font-Size="24px"> 
    <Columns> 
     <asp:BoundField DataField="Section" HeaderText="Section" SortExpression="Section" ControlStyle-CssClass="Section" /> 
     <asp:BoundField DataField="Name" HeaderText="Name" SortExpression="Name" /> 
     <asp:BoundField DataField="INIValue" HeaderText="INIValue" SortExpression="IniValue" /> 
     <asp:BoundField DataField="Description" HeaderText="Description" /> 
     <asp:BoundField DataField="Exposed" HeaderText="Exposed" /> 
     <asp:BoundField DataField="DataType" HeaderText="DataType" /> 
     <asp:BoundField DataField="DataFormat" HeaderText="DataFormat" /> 
    </Columns> 
</asp:GridView> 

答えて

1

BoundFieldにクラスを割り当てることができます。

<asp:BoundField DataField="DataFormat" HeaderText="DataFormat" 
    ItemStyle-CssClass="MyCLass" 
    HeaderStyle-CssClass="MyHeaderCLass" /> 
+0

これは私の問題で動作します。 – SkiaEsh

関連する問題