Akashsai raja

Akashsai raja

  • NA
  • 66
  • 506

I want to get Values From DB using Data And time & Dropdow

Nov 4 2017 3:05 AM
Hi to all I want to get Values From DB using Data And time & 2 Dropdown
 
Below the both CS and ASPX Code 

Thanx in Advance 
 
 
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="ajaxToolkit" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<style type="text/css">
.auto-style1 {
width: 27%;
margin-left: 10px;
}
.auto-style2 {
width: 208px;
}
.auto-style3 {
width: 407px;
}
</style>
</head>
<body>
<form id="form1" runat="server">
<div style="background-color:orange"><center>
<table class="auto-style1">
<tr>
<td class="auto-style3">Consular Id :</td>
<td class="auto-style2">
<asp:DropDownList ID="DropDownList1" runat="server" Height="16px" Width="122px" >
</asp:DropDownList>
</td>
</tr>
<tr>
<td class="auto-style3">Date :</td>
<td class="auto-style2">
<asp:TextBox ID="datetime" runat="server"></asp:TextBox>
<ajaxToolkit:CalendarExtender ID="CalendarExtender1" runat="server" TargetControlID="datetime" Format="dd-MM-yyyy"></ajaxToolkit:CalendarExtender>
</td>
</tr><asp:ScriptManager ID="ScriptManager1" runat="server"></asp:ScriptManager>
<tr>
<td class="auto-style3">Report Type:</td>
<td class="auto-style2">
<asp:DropDownList ID="DropDownList2" runat="server" Height="16px" style="margin-left: 0px" Width="123px">
<asp:ListItem Text="CDR" Value="1"></asp:ListItem>
<asp:ListItem Text="CCR" Value="2"></asp:ListItem>
<asp:ListItem Text="CER" Value="3"></asp:ListItem>
</asp:DropDownList>
</td>
</tr>
<tr>
<td class="auto-style3">&nbsp;</td>
<td class="auto-style2">
<asp:Button ID="Button1" runat="server" Height="26px" Text="Fetch Information" Width="115px" OnClick="Button1_Click" />
&nbsp;<asp:Label ID="Label1" runat="server" Text="Information" Visible="False"></asp:Label>
</td>
</tr>
<tr>
<td class="auto-style3">&nbsp;</td>
<td class="auto-style2">
<asp:GridView ID="GridView1" runat="server" AutoGenerateSelectButton="True" EnableSortingAndPagingCallbacks="False">
</asp:GridView>
</td>
</tr>
</table>
</center>
</div>
</form>
</body>
</html>
 
===========================================================
 
aspx.cs CODE 
 
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;
public partial class _Default : System.Web.UI.Page
{
public string conn = ConfigurationManager.ConnectionStrings["irisdb"].ConnectionString;
public string date;
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
bindropdown();
}
}
public void bindropdown()
{
try
{
using (SqlConnection con = new SqlConnection(conn))
{
con.Open();
SqlCommand cmd = new SqlCommand("Select coun_id from CDR", con);
DropDownList1.DataSource = cmd.ExecuteReader();
DropDownList1.DataTextField = "coun_id";
DropDownList1.DataBind();
con.Close();
}
}
catch (SqlException e)
{
Response.Write(e.Message);
}
}
protected void Button1_Click(object sender, EventArgs e)
{
try
{
using (SqlConnection con = new SqlConnection(conn))
{
if (DropDownList2.SelectedValue == "1")
{
con.Open();
SqlCommand cmd = new SqlCommand("Select *from CDR Where coun_id='" + DropDownList1.SelectedItem + "'", con);
SqlDataAdapter adpt = new SqlDataAdapter(cmd);
DataSet ds = new DataSet();
adpt.Fill(ds);
SqlDataReader dr = cmd.ExecuteReader();
GridView1.DataSource = ds;
GridView1.DataBind();
GridView1.Visible = true;
con.Close();
}
else if (DropDownList2.SelectedValue == "2")
{
con.Open();
SqlCommand cmd = new SqlCommand("Select *from CCR Where coun_id='" + DropDownList1.SelectedItem + "'", con);
SqlDataAdapter adpt = new SqlDataAdapter(cmd);
DataSet ds = new DataSet();
adpt.Fill(ds);
SqlDataReader dr = cmd.ExecuteReader();
GridView1.DataSource = ds;
GridView1.DataBind();
GridView1.Visible = true;
con.Close();
}
else if (DropDownList2.SelectedValue == "3")
{
con.Open();
SqlCommand cmd = new SqlCommand("Select *from CER Where coun_id='" + DropDownList1.SelectedItem + "'", con);
SqlDataAdapter adpt = new SqlDataAdapter(cmd);
DataSet ds = new DataSet();
adpt.Fill(ds);
SqlDataReader dr = cmd.ExecuteReader();
GridView1.DataSource = ds;
GridView1.DataBind();
GridView1.Visible = true;
con.Close();
}
}
}
catch (Exception ex)
{
Response.Write(ex.Message);
}
}
}
 
I Want to Get 2 Values in dropdown , 1 textbox ( Selected  date By user ) to display in GridView    
 Anyone Help me !!  
 
 

 

Answers (1)