Night_Wolf1619
New Member
I am working on a project where i have to show report according to the selected value from dropdown list and date range.i want when i select value from dropdown list and date range it can show the me data for that value according to date range. my code for report page:\[code\] <div id="Portal" runat="server"> <asp:Label ID="lblPortal" runat="server" Text="Select Portal"/> <aspropDownList ID="ddlPortal2" runat="server" onselectedindexchanged="ddlPortal2_SelectedIndexChanged" AutoPostBack="True"> <asp:ListItem>Select</asp:ListItem> <asp:ListItem>TRAVELONG</asp:ListItem> <asp:ListItem>ONETRAVEL</asp:ListItem> <asp:ListItem>.UK-BSP</asp:ListItem> <asp:ListItem>.CV-YYZ</asp:ListItem> <asp:ListItem>.CV-YVR</asp:ListItem> </aspropDownList> <asp:Label ID="lbFrom" Text="From" runat="server" /> <asp:TextBox ID="tbFrom" runat="server" /> <asp:RequiredFieldValidator ID="rfvFrom" runat="server" ControlToValidate="tbFrom" ErrorMessage="Enter Valid Date">*</asp:RequiredFieldValidator> <asp:Label ID="lblto" Text="To" runat="server" /> <asp:TextBox ID="tbTo" runat="server" /> <asp:RequiredFieldValidator ID="rfvTo" runat="server" ControlToValidate="tbTo" ErrorMessage="Enter To date">*</asp:RequiredFieldValidator>\[/code\] &
Second div on the same page:\[code\]<div id="Main" style="margin-left: 80px" runat="server"><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:TemplateField HeaderText="Date"> <ItemTemplate> <asp:Label ID="lblDateTime" runat="server" Text='<%# Eval("DateTime","{0:d}") %>'></asp:Label> </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> <AlternatingRowStyle BackColor="White" /> <EditRowStyle BackColor="#2461BF" /> <FooterStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" /> <HeaderStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" /> <PagerStyle BackColor="#2461BF" ForeColor="White" HorizontalAlign="Center" /> <RowStyle BackColor="#EFF3FB" /> <SelectedRowStyle BackColor="#D1DDF1" Font-Bold="True" ForeColor="#333333" /> <SortedAscendingCellStyle BackColor="#F5F7FB" /> <SortedAscendingHeaderStyle BackColor="#6D95E1" /> <SortedDescendingCellStyle BackColor="#E9EBEF" /> <SortedDescendingHeaderStyle BackColor="#4870BE" /> </asp:GridView></div>\[/code\]Now Code behind:\[code\] protected void Page_Load(object sender, EventArgs e){ try { if (!Page.IsPostBack) { //Fill dataset with database da = new SqlDataAdapter(sql, con); ds = new DataSet(); da.Fill(ds); ddlPortal2.DataSource = ds.Tables[0]; ddlPortal2.DataTextField = "Portal"; ddlPortal2.DataValueField = "ID"; ddlPortal2.DataBind(); GridViewBind(); //show all Data from database on Page cmd = new SqlCommand("select * from Form3", con); da = new SqlDataAdapter(cmd); dt.Clear(); con.Open(); da.Fill(dt); if (dt.Rows.Count > 0) { GridView1.DataSource = dt; GridView1.DataBind(); } con.Close(); } } catch (Exception ex) { Response.Write(ex.ToString()); } }public void GridViewBind(){ con.Open(); da = new SqlDataAdapter("select * from Form3 where ID=" + ddlPortal2.SelectedValue + " and CONVERT(VARCHAR(25), [DateTime], 101) between '" + tbFrom.Text + "' and '" + tbTo.Text + "'" , con); ds = new DataSet(); da.Fill(ds); GridView1.DataSource = ds.Tables[0]; GridView1.DataBind(); con.Close();} protected void btnSearch_Click(object sender, EventArgs e){ this.GridViewBind();}\[/code\]
Second div on the same page:\[code\]<div id="Main" style="margin-left: 80px" runat="server"><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:TemplateField HeaderText="Date"> <ItemTemplate> <asp:Label ID="lblDateTime" runat="server" Text='<%# Eval("DateTime","{0:d}") %>'></asp:Label> </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> <AlternatingRowStyle BackColor="White" /> <EditRowStyle BackColor="#2461BF" /> <FooterStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" /> <HeaderStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" /> <PagerStyle BackColor="#2461BF" ForeColor="White" HorizontalAlign="Center" /> <RowStyle BackColor="#EFF3FB" /> <SelectedRowStyle BackColor="#D1DDF1" Font-Bold="True" ForeColor="#333333" /> <SortedAscendingCellStyle BackColor="#F5F7FB" /> <SortedAscendingHeaderStyle BackColor="#6D95E1" /> <SortedDescendingCellStyle BackColor="#E9EBEF" /> <SortedDescendingHeaderStyle BackColor="#4870BE" /> </asp:GridView></div>\[/code\]Now Code behind:\[code\] protected void Page_Load(object sender, EventArgs e){ try { if (!Page.IsPostBack) { //Fill dataset with database da = new SqlDataAdapter(sql, con); ds = new DataSet(); da.Fill(ds); ddlPortal2.DataSource = ds.Tables[0]; ddlPortal2.DataTextField = "Portal"; ddlPortal2.DataValueField = "ID"; ddlPortal2.DataBind(); GridViewBind(); //show all Data from database on Page cmd = new SqlCommand("select * from Form3", con); da = new SqlDataAdapter(cmd); dt.Clear(); con.Open(); da.Fill(dt); if (dt.Rows.Count > 0) { GridView1.DataSource = dt; GridView1.DataBind(); } con.Close(); } } catch (Exception ex) { Response.Write(ex.ToString()); } }public void GridViewBind(){ con.Open(); da = new SqlDataAdapter("select * from Form3 where ID=" + ddlPortal2.SelectedValue + " and CONVERT(VARCHAR(25), [DateTime], 101) between '" + tbFrom.Text + "' and '" + tbTo.Text + "'" , con); ds = new DataSet(); da.Fill(ds); GridView1.DataSource = ds.Tables[0]; GridView1.DataBind(); con.Close();} protected void btnSearch_Click(object sender, EventArgs e){ this.GridViewBind();}\[/code\]