Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

Hi,

 

Does anyone know if it is possible to bind data directly to a label?

 

I want to retrieve some information from an SQL database and bind this to a label (writing in vb by the way) so the information can be used to control things within the website.

 

I have a series of user controls that I want only to be visible if a certain value (retrieved from the sql database) is equal to a certain value. This is essential to the site as it will prevent people from attempting to do things they should not be able to do.

 

I have all the if statements ready within my application logic to control what I have described, the only thing I am missing is the data.

 

I have tried binding to a datalist with a label embedded in it, this works fine but then the label becomes inaccessible to any thing else within the webpage. I have also tried creating a global variable, but again the problem is assigning the value retrieved from the database to the global variable.

 

Any ideas anyone?

 

 

:-\

Posted

I can use either, I only picked Label as it was the first thing that came to my head, a textbox would be fine, as I would set the visibility property to "False" anyway.

 

Do you know how to bind to a textbox? If you did that would be fantastic.

 

Cheers

 

Ash

Posted

I have tried your method in several ways and unfortunately I still have the same problem.

 

I followed your code and had:

 

<asp:TextBox id="ext1" Width="80px" Runat="server" MaxLength=8 Text='<%# Container.DataItem("expression")%>' >

 

But to get this to work I had to have it within <asp:repeater> tags.

 

As soon as it is inside the repeater tag the page displays the data within the text box, but when I then try and assign the text box to a label or a variable:

 

Dim VariableX As Integer / or Dim VariableX As String

VariableX = ext1.Text

 

I get:

 

Object reference not set to an instance of an object.

 

I am quite stuck on this one, and even though I have got round the initial problem by a long-winded and inefficient method of filling another dataset with data and counting the number of results and making conditional statements dependant on the result, I still want to find out how to bind data to a label and then extract that data and use it throughout my applications. I am sure it can be done, I just can't quite get my head around it yet.

 

Any suggestions?

 

Ash

Posted

Yeah, if it's inside a repeater, you cant reference it like that..

 

This is how I did it when with a repeater;

 

Dim DisplayNotesValue As Label = CType(rpAct22.Items(i).FindControl("lblDisplayNotes"), WebControls.Label)

 

with rpAct22 being the name of the repeater. lblDisplayNotes name of the label.

 

Or for textbox:

 

Dim InternalNotesBox As TextBox = CType(rpAct22.Items(i).FindControl("txtInternalNotes"), WebControls.TextBox)

 

Is this what you want to do?

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...