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
Thanx in Advance
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="ajaxToolkit" %>
.auto-style1 {
width: 27%;
margin-left: 10px;
}
.auto-style2 {
width: 208px;
}
.auto-style3 {
width: 407px;
}
| Consular Id : | |
| Date : | |
| Report Type: | |
===========================================================
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 !!
Rajkiran SwainPosted Nov 4, 2017, 3:55 AM