0

I need to show my data in a gridview based on my dropdown list, fromdate and todate when data is entered in the textbox. How can I do that? What I have done till now is I created two pages. In first page I have a dropdown list and a form. When I select value from drop-down list the form for the selected value appears and user can enter details in it and submits that form. After submitting the data store in the database. In second page I have a grid view where stored value can be seen, dropdown list, from date and to date textbox now what I want is to show the records in the gridview based on my dropdown selection, fromdate and todate.

Code for second form:

<asp:DropDownList ID="ddlPortal" runat="server" AutoPostBack="True" 
       onselectedindexchanged="ddlPortal_SelectedIndexChanged">
       <asp:ListItem>TRAVELONG</asp:ListItem>
       <asp:ListItem>ONETRAVEL</asp:ListItem>
       <asp:ListItem>.UK-BSP</asp:ListItem>
       <asp:ListItem>.CA-YYZ</asp:ListItem>
       <asp:ListItem>.CA-YVR</asp:ListItem>
       <asp:ListItem>Partial MCO Refund</asp:ListItem>
   </asp:DropDownList>
   <asp:Label ID="lbFrom" Text="From" runat="server" />&nbsp;<asp:TextBox ID="tbFrom" runat="server" />
    &nbsp;<asp:Label ID="lblto" Text="To" runat="server" />&nbsp;<asp:TextBox ID="tbTo" runat="server" />
    &nbsp;<asp:Button ID="btnSearch" runat="server" Text="Search" 
    onclick="btnSearch_Click" />

Gridview details:

 <asp:GridView ID="GridView1" runat="server" CellPadding="4" ForeColor="#333333" 
        GridLines="None" onrowcommand="GridView1_RowCommand" 
        AutoGenerateColumns="False">
        <Columns>
       <asp:TemplateField HeaderText="Query">
            <itemtemplate>
            <asp:LinkButton CommandName="cmdBind"  runat="server"  Text='<%#Eval("ID")%>' ID="ID" ToolTip='<%#Eval("ID")%>'>LinkButton
            </asp:LinkButton>                                                                   
            </itemtemplate>
            </asp:TemplateField>
       <asp:BoundField DataField="Portal" HeaderText="Portal" />
        <asp:BoundField DataField="TID" HeaderText="TID" />
        <asp:BoundField DataField="PNR" HeaderText="PNR" />
        <asp:BoundField DataField="TicketNumber" HeaderText="Ticket Number" />
        <asp:BoundField DataField="ESACCode" HeaderText="ESACCode" />
        <asp:BoundField DataField="WaiverCode" HeaderText="WaiverCode" />
        <asp:BoundField DataField="Remarks" HeaderText="Remarks" />
        <asp:BoundField DataField="UnusedTicketAmount" HeaderText="UnusedTicketAmount" />
        <asp:BoundField DataField="ddlUnusedAmount" HeaderText="ddlUnusedAmount" />
        <asp:BoundField DataField="AirlinePenality" HeaderText="AirlinePenality" />
        <asp:BoundField DataField="ddlAirlinePenality" HeaderText="ddlAirlinePenality" />
        <asp:BoundField DataField="NetRefundProcess" HeaderText="NetRefundProcess" />
        <asp:BoundField DataField="ddlNetRefundProcess" HeaderText="ddlNetRefundProcess" />
        <asp:BoundField DataField="RefundableCommission" HeaderText="RefundableCommission" />
        <asp:BoundField DataField="ddlRefundableCommission" HeaderText="ddlRefundableCommission" />
        <asp:BoundField DataField="CouponRefunded" HeaderText="CouponRefunded" />
        <asp:BoundField DataField="RefundType" HeaderText="RefundType" />
    </Columns>       

I want to write code on click event of button but I don't know how. Can you help me on this?

.cs file:

protected void btnSearch_Click(object sender, EventArgs e)
{

}  
Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
amitesh
  • 766
  • 5
  • 17
  • 39

1 Answers1

0

If you are using DataTable for binding your GridView then, you can filter the data & bind your GridView again.

You can use: DataView.RowFilter Property for filtering data.

Eg.:

DataTable dt= GetData();
DataView dv = dt.DefaultView;
dv.RowFilter = "Portal= '" + ddlPortal.SelectedValue.Trim() + "'" 
GridView1.DataSource=dv;
GridView1.DataBind();

Also, you can use LINQ to filter data:

DataTable dt= GetData();
EnumerableRowCollection<DataRow> query =
    from row in dt.AsEnumerable()
    where row.Field<String>("Portal") == ddlPortal.SelectedValue.Trim()
    select row;

DataView dv = query.AsDataView();
GridView1.DataSource=dv;
GridView1.DataBind();
Kapil Khandelwal
  • 15,958
  • 2
  • 45
  • 52
  • i have to bind data on click event of button or create a method for it – amitesh Mar 20 '13 at 11:46
  • It depends on you. You can create a method. And on button click, call it & pass the required parameters to it. – Kapil Khandelwal Mar 20 '13 at 11:50
  • what is the use of GetData() – amitesh Mar 20 '13 at 11:53
  • Its your method for getting data form source (Database). – Kapil Khandelwal Mar 20 '13 at 11:57
  • i didn't get u i already get data in my gridview from database suppose i select TRAVELONG from dropdown list on my second page i want to show only Data releter to TRAVELONG in grid i hope u understand what i want – amitesh Mar 20 '13 at 12:06
  • i have found one solution but it is only for dropdown list i also want date range on it this is the link which help me http://www.c-sharpcorner.com/UploadFile/718fc8/how-to-show-record-into-gridview-using-dropdownlist-in-web-a/ – amitesh Mar 20 '13 at 12:44