Displaying Multiple Database in web using Gridview AJAX
Displaying Multiple Database in web using Gridview
--------------------
Aspx Designing
--------------------
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="DataBase.aspx.cs" Inherits="AJAX.DataBase" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<link href="css/bootstrap.css" rel="stylesheet" type="text/css" />
</head>
<body>
<form id="form1" runat="server">
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<asp:DropDownList ID="DDLAjax" runat="server" Height="16px" Width="117px">
</asp:DropDownList>
<asp:Button ID="Button1" runat="server" onclick="Button1_Click" Text="Show"
Width="95px" />
<br />
<asp:GridView ID="GridView1" runat="server">
</asp:GridView>
</ContentTemplate>
</asp:UpdatePanel>
<table><tr><td>
<asp:Button ID="btnlogout" runat="server" onclick="btnlogout_Click"
Text="Logout" />
<asp:ImageButton ID="ImageButton1" runat="server"
ImageUrl="~/Images/excel.jpg" onclick="ImageButton1_Click" Width="50px" />
</td></tr></table>
</form>
</body>
</html>
-------------------
Aspx.cs code
-------------------
Library 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;
using System.IO;
namespace AJAX
{
public partial class DataBase : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
this.DDLAjax.Items.Add("Final_Table");
this.DDLAjax.Items.Add("Table1");
this.DDLAjax.Items.Add("Final_Table2");
this.DDLAjax.Items.Add("Final_Table3");
}
}
protected void Button1_Click(object sender, EventArgs e)
{
SqlConnection con = new SqlConnection(@"Data Source=Ashish;Initial Catalog=GRAPES;User ID=sa;Password=ashishsql");
con.Open();
SqlCommand cmd = null;
if (this.DDLAjax.SelectedItem.Text == "Final_Table")
{
cmd = new SqlCommand("Select * from Final_Table ", con);
}
if (this.DDLAjax.SelectedItem.Text == "Table1")
{
cmd = new SqlCommand("select * from Table1 ", con);
}
if (this.DDLAjax.SelectedItem.Text == "Final_Table2")
{
cmd = new SqlCommand("select * from Final_Table2",con);
}
if (this.DDLAjax.SelectedItem.Text == "Final_Table3")
{
cmd = new SqlCommand("select * from Final_Table3", con);
}
this.GridView1.DataSource = cmd.ExecuteReader();
this.GridView1.DataBind();
}
protected void btnlogout_Click(object sender, EventArgs e)
{
Session.Clear();
Session.Abandon();
Response.Redirect("Login.aspx", true);
}
Comments
Post a Comment