By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,952 Members | 1,617 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,952 IT Pros & Developers. It's quick & easy.

limit what the gridview shows based on what is searched for

P: 48
I have a gridview that is bound to a database. I also have fields where you can search for something and then it show up in the gridview based on what you searched for. ex, you can search for pro that starts with 123 and everything that starts with those numbers will come up. I also have a field called invoice number. however, i want to only allow it to show in the gridview if it is searched for. right now this is my code for the gridview.

Expand|Select|Wrap|Line Numbers
  1. <asp:GridView ID="GridView1" PageIndex="0" EnableSortingAndPagingCallbacks="True" CssClass="GridView" AllowPaging="false" PageSize="30" AllowSorting="true" OnSorting="gvFreightBills_Sorting" runat="server" CellPadding="1" CellSpacing="2" GridLines="Vertical" HorizontalAlign="Left" AutoGenerateColumns="false" RowStyle-Height="19" DataKeyNames="DATE_ENT,CARRIER,PRO">
  2.  
  3.  
  4.                     <AlternatingRowStyle BackColor="#CCCCCC" />
  5.                     <Columns>
  6.                         <asp:CommandField ControlStyle-CssClass="GridViewSelectButton" HeaderStyle-Width="40" ItemStyle-Width="40" SelectText="Select" ShowSelectButton="true" ItemStyle-HorizontalAlign="center"></asp:CommandField>
  7.                         <asp:BoundField ItemStyle-CssClass="GVCol" DataField="SHIP_DATE" HeaderText="Ship Date" ControlStyle-Width="70" HeaderStyle-Width="70" ItemStyle-Width="70" SortExpression="tbl_Bills.[Date]" DataFormatString="{0:d}"></asp:BoundField>
  8.                         <asp:BoundField ItemStyle-CssClass="GVCol" DataField="DATE_ENT" HeaderText="Date Ent." ControlStyle-Width="70" HeaderStyle-Width="70" ItemStyle-Width="70" SortExpression="tbl_Bills.[DATE ENT]" DataFormatString="{0:d}"></asp:BoundField>
  9.                         <asp:BoundField ItemStyle-CssClass="GVCol" DataField="CARRIER" HeaderText="Carrier" ReadOnly="True" SortExpression="CARRIER" HeaderStyle-Width="50" ItemStyle-Width="50"></asp:BoundField>
  10.                         <asp:BoundField ItemStyle-CssClass="GVCol" DataField="PRO" HeaderText="PRO" ControlStyle-Width="105" HeaderStyle-Width="105" ReadOnly="True" SortExpression="PRO"></asp:BoundField>
  11.                         <asp:BoundField ItemStyle-CssClass="GVCol" DataField="spec_fedinv" HeaderText="Invoice No" SortExpression="tbl_bills.[spec_fedinv]"></asp:BoundField>
  12.                         <asp:BoundField ItemStyle-CssClass="GVCol" DataField="SHIPPER" HeaderText="Shipper" ControlStyle-Width="50" HeaderStyle-Width="70" ItemStyle-Width="70" SortExpression="SHIPPER" ></asp:BoundField>
  13.                         <asp:BoundField ItemStyle-CssClass="GVCol" DataField="CONS" HeaderText="Consignee" SortExpression="CONS" ControlStyle-Width="70" HeaderStyle-Width="70" ItemStyle-Width="70"></asp:BoundField>
  14.                         <asp:BoundField ItemStyle-CssClass="GVCol" DataField="F_B" HeaderText="BOL No" SortExpression="F_B"></asp:BoundField>
  15.                         <asp:BoundField ItemStyle-CssClass="GVCol" DataField="LOC" HeaderText="Loc" SortExpression="LOC"></asp:BoundField>
  16.                         <asp:BoundField ItemStyle-CssClass="GVCol" DataField="PCS" HeaderText="PCS" SortExpression="PCS" ControlStyle-Width="30" HeaderStyle-Width="30" ItemStyle-Width="30"></asp:BoundField>
  17.                         <asp:BoundField ItemStyle-CssClass="GVCol" DataField="WT" HeaderText="WT" SortExpression="WT" ControlStyle-Width="30" HeaderStyle-Width="30" ItemStyle-Width="30"></asp:BoundField>
  18.                         <asp:BoundField ItemStyle-CssClass="GVCol" DataField="NET_CHGS" HeaderText="NET Chgs." ControlStyle-Width="60" HeaderStyle-Width="60" ItemStyle-Width="60" SortExpression="NET_CHGS" DataFormatString="{0:$0.00}"></asp:BoundField>
  19.                         <asp:BoundField ItemStyle-CssClass="GVCol" DataField="DATE_PAID" HeaderText="Date Paid" ControlStyle-Width="70" HeaderStyle-Width="70" ItemStyle-Width="70" SortExpression="tbl_Bills.[DATE PAID]" DataFormatString="{0:d}"></asp:BoundField>
  20.                         <asp:BoundField ItemStyle-CssClass="GVCol" DataField="CK_NO" HeaderText="CK No." SortExpression="tbl_Bills.[CK NO]"></asp:BoundField>
  21.                     </Columns>
  22.                     <FooterStyle BackColor="#CCCCCC" />
  23.                     <HeaderStyle BackColor="Black" Font-Bold="True" ForeColor="White" />
  24.                     <RowStyle Height="19px"></RowStyle>
  25.                     <SelectedRowStyle BackColor="#000099" Font-Bold="True" ForeColor="White" />
  26.                 </asp:GridView>
this is what i have for my textboxes
Expand|Select|Wrap|Line Numbers
  1. <div class="Spacer5"></div>
  2.             <div class="Dotted40"></div>
  3.             <div class="Spacer5"></div>
  4.  
  5.                 <div class="divFBQueryLineItemWrapper">
  6.                     <div class="divFBQueryLeftColumn">
  7.                         Pro: 
  8.                     </div>
  9.                     <div class="divFBQueryRightColumn">
  10.                         <asp:TextBox ID="tbProNumber" Width="115px" runat="server"></asp:TextBox>
  11.  
  12.                     </div>
  13.                     <div style="clear: both"></div>
  14.                 </div>
  15.  
  16.  
  17.                 <div class="Spacer5"></div>
  18.                 <div class="divFBQueryLineItemWrapper">
  19.                     <div class="divFBQueryLeftColumn">
  20.                         Invoice No: 
  21.                     </div>
  22.                     <div class="divFBQueryRightColumn">
  23.                         <asp:TextBox ID="tbInvoiceNo" Width="115px" runat="server"></asp:TextBox>
  24.  
  25.                     </div>
  26.                     <div style="clear: both"></div>
  27.                 </div>
  28.  
  29.                 <div class="Spacer5"></div>
  30.                 <div class="divFBQueryLineItemWrapper">
  31.                     <div class="divFBQueryLeftColumn">
  32.                         Bill of Lading: 
  33.                     </div>
  34.                     <div class="divFBQueryRightColumn">
  35.                         <asp:TextBox ID="tbBillOfLadingNumber" Width="115px" runat="server"></asp:TextBox>
  36.  
  37.                     </div>
  38.                     <div style="clear: both"></div>
i also have a search button. I think that i would put something in my search button click event that says if tbinvoice is blank then do not show the row for invoice in the gridview, else show it. but how i would i code that? please help!
Oct 6 '15 #1

✓ answered by lillyehrhart

here is my solution
Expand|Select|Wrap|Line Numbers
  1. If tbInvoiceNo.Text = "" Then
  2.             GridView1.Columns(5).Visible = False
  3.         Else
  4.             GridView1.Columns(5).Visible = True
  5.         End If

Share this Question
Share on Google+
3 Replies


P: 48
nevermind i figured it out.
Oct 6 '15 #2

Rabbit
Expert Mod 10K+
P: 12,347
Could you post your solution in case someone runs into the same issue?
Oct 6 '15 #3

P: 48
here is my solution
Expand|Select|Wrap|Line Numbers
  1. If tbInvoiceNo.Text = "" Then
  2.             GridView1.Columns(5).Visible = False
  3.         Else
  4.             GridView1.Columns(5).Visible = True
  5.         End If
Oct 8 '15 #4

Post your reply

Sign in to post your reply or Sign up for a free account.