C# .NET - Show Data from database on labels inside the panel on mouseover event

Asked By Harish on 31-Dec-10 01:30 AM
Plz Explain me how to show data on lables in panel from database on mouseover event in asp.net using c#
Reena Jain replied to Harish on 31-Dec-10 01:43 AM
hi,

just use this code on mouse over event

SqlConnection conn = new SqlConnection(connectionString);
SqlCommand comm = new SqlCommand("select * from mytable", conn);
comm.Connection.Open();
SqlDataReader r = 
  comm.ExecuteReader(CommandBehavior.CloseConnection);
while(r.Read()) 
{
  lable1.Text = r.GetString(0);
}
r.Close();
conn.Close();

hope this will help you
Sagar P replied to Harish on 31-Dec-10 02:10 AM
Use this code on mouse over of data;

SqlConnection con = new SqlConnection("YourConnectionString");

if (con != null)

{

using (con)

{

if (con.State == System.Data.ConnectionState.Closed)

{

con.Open();

}

string query = "Select * from yourTable";

SqlDataAdapter da = new SqlDataAdapter(query, con);

DataSet ds = new DataSet();

da.Fill(ds);

label1.Text = ds.Tables[0].Rows[0][1].ToString();

label2.Text = ds.Tables[0].Rows[0][2].ToString();

}
}
Vivek Jagga replied to Harish on 31-Dec-10 02:25 AM
Harish,

you'll find the http://www.asp.net/ajaxquite usefull. It uses ASP.NET AJAX and the ASP.NET AJAX Control Toolkit.

Manu replied to Harish on 31-Dec-10 04:37 AM

Try This, This code will fetch data from the SQL Server database(using javascript) and onmouse over it will show in the label -

HTML Code :

<html xmlns="http://www.w3.org/1999/xhtml" >

<head runat="server">

<title>Javascript Sample</title>

<script language="JavaScript" type="text/javascript">

function DataFromSQL()

{

var connection = new ActiveXObject("ADODB.Connection") ;

var connectionstring="Data Source=IN-AP002;Initial Catalog=VMS;User ID=VMS_Users;Password=vmsapps123;Provider=SQLOLEDB";

connection.Open(connectionstring);

var rs = new ActiveXObject("ADODB.Recordset");

var count=1;

rs.Open("SELECT * FROM TestTable", connection);

rs.MoveFirst

while(!rs.eof)

{

document.getElementById("Label"+count).innerText=rs.fields(1);

rs.movenext;

count++;

}

rs.close;

connection.close;

}

</script>

</head>

<body>

<form id="form1" runat="server">

<div>

<asp:Panel ID="Panel1" runat="server" Height="101px" Width="361px">

<asp:Label ID="Label1" runat="server" Text="Label" Width="104px"></asp:Label><br />

<asp:Label ID="Label2" runat="server" Text="Label" Width="104px"></asp:Label><br />

<asp:Label ID="Label3" runat="server" Text="Label" Width="104px"></asp:Label></asp:Panel>

 

<asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="OK"/></div>

</form>

</body>

</html>

.CS File :

Label1.Attributes.Add("onmouseover", "DataFromSQL()");