TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
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"> </td>
<td class="auto-style2">
<asp:Button ID="Button1" runat="server" Height="26px" Text="Fetch Information" Width="115px" OnClick="Button1_Click" />
<asp:Label ID="Label1" runat="server" Text="Information" Visible="False"></asp:Label>
</td>
</tr>
<tr>
<td class="auto-style3"> </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 !!
Reply
Answers (
1
)
How to call webmetod in master page ?
chat application in signal r using database