Hey akhter,
Please refer below sample.
HTML
From :
<asp:TextBox runat="server" ID="txtFromDate" />
To :
<asp:TextBox runat="server" ID="txtToDate" />
<asp:Button Text="Search" runat="server" OnClick="Search" />
<asp:GridView runat="server" ID="Gridview1">
<Columns>
<asp:BoundField DataField="LastName" HeaderText="LastName" />
<asp:BoundField DataField="FirstName" HeaderText="FirstName" />
<asp:BoundField DataField="BirthDate" HeaderText="BirthDate" />
<asp:BoundField DataField="City" HeaderText="City" />
</Columns>
</asp:GridView>
<br />
<asp:GridView runat="server" ID="Gridview2">
<Columns>
<columns>
<asp:BoundField DataField="LastName" HeaderText="LastName" />
<asp:BoundField DataField="FirstName" HeaderText="FirstName" />
<asp:BoundField DataField="BirthDate" HeaderText="BirthDate" />
<asp:BoundField DataField="City" HeaderText="City" />
</columns>
</Columns>
</asp:GridView>
Namespaces
C#
using System.Data;
using System.Data.SqlClient;
using System.Configuration;
VB.Net
Imports System.Data.SqlClient
Imports System.Data
Code
C#
protected void Page_Load(object sender, EventArgs e)
{
if (!this.IsPostBack)
{
string constr = ConfigurationManager.ConnectionStrings["constr"].ConnectionString;
SqlConnection con = new SqlConnection(constr);
SqlCommand cmd = new SqlCommand("SELECT LastName, FirstName, BirthDate, City FROM Employees", con);
SqlDataAdapter da = new SqlDataAdapter(cmd);
DataTable dt = new DataTable();
da.Fill(dt);
Gridview1.DataSource = dt;
Gridview1.DataBind();
Gridview2.DataSource = dt;
Gridview2.DataBind();
}
}
protected void Search(object sender, EventArgs e)
{
string constr = ConfigurationManager.ConnectionStrings["constr"].ConnectionString;
SqlConnection con = new SqlConnection(constr);
SqlCommand cmd = new SqlCommand("getEmployeeDetails");
cmd.Parameters.AddWithValue("@FromDate", DateTime.Parse(txtFromDate.Text).ToString("yyyy-MM-dd ", System.Globalization.CultureInfo.InvariantCulture));
cmd.Parameters.AddWithValue("@ToDate", DateTime.Parse(txtToDate.Text).ToString("yyyy-MM-dd ", System.Globalization.CultureInfo.InvariantCulture));
cmd.Connection = con;
cmd.CommandType = CommandType.StoredProcedure;
SqlDataAdapter da = new SqlDataAdapter(cmd);
DataTable dt = new DataTable();
da.Fill(dt);
Gridview1.DataSource = dt;
Gridview1.DataBind();
SqlCommand cmd1 = new SqlCommand("getEmployeeDetails1");
cmd1.Parameters.AddWithValue("@FromDate", DateTime.Parse(txtFromDate.Text).ToString("yyyy-MM-dd ", System.Globalization.CultureInfo.InvariantCulture));
cmd1.Parameters.AddWithValue("@ToDate", DateTime.Parse(txtToDate.Text).ToString("yyyy-MM-dd ", System.Globalization.CultureInfo.InvariantCulture));
cmd1.Connection = con;
cmd1.CommandType = CommandType.StoredProcedure;
SqlDataAdapter da1 = new SqlDataAdapter(cmd1);
DataTable dt1 = new DataTable();
da1.Fill(dt1);
Gridview2.DataSource = dt1;
Gridview2.DataBind();
}
VB.Net
Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs) Handles Me.Load
If Not Me.IsPostBack Then
Dim constr As String = ConfigurationManager.ConnectionStrings("constr").ConnectionString
Dim con As SqlConnection = New SqlConnection(constr)
Dim cmd As SqlCommand = New SqlCommand("SELECT LastName, FirstName, BirthDate, City FROM Employees", con)
Dim da As SqlDataAdapter = New SqlDataAdapter(cmd)
Dim dt As DataTable = New DataTable()
da.Fill(dt)
Gridview1.DataSource = dt
Gridview1.DataBind()
Gridview2.DataSource = dt
Gridview2.DataBind()
End If
End Sub
Protected Sub Search(ByVal sender As Object, ByVal e As EventArgs)
Dim constr As String = ConfigurationManager.ConnectionStrings("constr").ConnectionString
Dim con As SqlConnection = New SqlConnection(constr)
Dim cmd As SqlCommand = New SqlCommand("getEmployeeDetails")
cmd.Parameters.AddWithValue("@FromDate", DateTime.Parse(txtFromDate.Text).ToString("yyyy-MM-dd ", System.Globalization.CultureInfo.InvariantCulture))
cmd.Parameters.AddWithValue("@ToDate", DateTime.Parse(txtToDate.Text).ToString("yyyy-MM-dd ", System.Globalization.CultureInfo.InvariantCulture))
cmd.Connection = con
cmd.CommandType = CommandType.StoredProcedure
Dim da As SqlDataAdapter = New SqlDataAdapter(cmd)
Dim dt As DataTable = New DataTable()
da.Fill(dt)
Gridview1.DataSource = dt
Gridview1.DataBind()
Dim cmd1 As SqlCommand = New SqlCommand("getEmployeeDetails1")
cmd1.Parameters.AddWithValue("@FromDate", DateTime.Parse(txtFromDate.Text).ToString("yyyy-MM-dd ", System.Globalization.CultureInfo.InvariantCulture))
cmd1.Parameters.AddWithValue("@ToDate", DateTime.Parse(txtToDate.Text).ToString("yyyy-MM-dd ", System.Globalization.CultureInfo.InvariantCulture))
cmd1.Connection = con
cmd1.CommandType = CommandType.StoredProcedure
Dim da1 As SqlDataAdapter = New SqlDataAdapter(cmd1)
Dim dt1 As DataTable = New DataTable()
da1.Fill(dt1)
Gridview2.DataSource = dt1
Gridview2.DataBind()
End Sub
Screenshot