putting c# variable value from code behind into asp.net label

liunx

Guest
hello!

i have a question...

i have an asp.net page and the code behind is c# that connects to the database. i am retrieving a datarow of names, but for for testing purposes, i am just retrieving one name ("DW30") from the datarow and storing it in a variable label1String:

public string label1String;

private void Page_Load(object sender, System.EventArgs e)
{
//create the database connection
OleDbConnection aConnection = new OleDbConnection
("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=c:\\intetpub\\wwwroot\\christieMarketingSurvey\\testing.mdb;" +
"user id=; password=;");

try
{
aConnection.Open();

OleDbCommand aCommand = aConnection.CreateCommand();
aCommand.Connection = aConnection;

OleDbDataAdapter anAdapter = new OleDbDataAdapter();
DataSet aDataSet = new DataSet();

aCommand.CommandText ="SELECT Name FROM tblProduct, tblProjector " +
"WHERE tblProduct.Product_ID = tblProjector.Projector_ID " +
"AND Type='P' ORDER BY tblProjector.Lumens ASC";
anAdapter.SelectCommand = aCommand;
anAdapter.Fill(aDataSet, "tblProduct");

DataRow[] labelRow = aDataSet.Tables["tblProduct"].Select("Name = 'DW30'");

label1String = Convert.ToString(labelRow[0]["Name"]);

aConnection.Close();
}
catch(Exception myException)
{
aConnection.Close();
Console.WriteLine(myException.ToString());
}

Page.DataBind();
}

---

then in my asp.net page, i have a layer in which i have a label that i want to contain the variable label1String (from the code behind), which i have written below:

...

<td width="80" height="20" bgcolor="#ffffff">
<DIV align="center" id="DW30" style="FONT-SIZE: 10px; WIDTH: 80px; COLOR: #ffffff; FONT-FAMILY: arial; POSITION: absolute; HEIGHT: 20px; BACKGROUND-COLOR: #716d93; layer-background-color: #716d93">
<asp:Label ID="Label1" text= <%# label1String %> Runat=server></asp:Label>
</DIV>
</td>
...

but nothing is showing up...any advice? is my syntax wrong?

thank you very much!!

kind regards,
Quinn*i'm not 100% sure, but i think you need to add the '.text' to label1String ... Do you get any errors when debugging?


label1String.text = Convert.ToString(labelRow[0]["Name"]);
 
Back
Top