Databind a Label (or Literal), proper way?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Brian Simmons

    #1

    Databind a Label (or Literal), proper way?

    I'll try to keep this short & sweet and hopefully get the direction I'm
    looking for.

    I'll drop a SqlDatasource onto a webform. Configure it to use a stored
    proc, perhaps have the parameters be QueryString parms or Session variables,
    whatever the situation calls for.

    The Stored Proc will return one row of data, let's say FirstName & LastName,
    John Smith.

    I drop a Label (or Literal) onto the webform.

    I would like the Label's Text property to be set to FirstName.

    What/where is the proper way to hook this up?

    In the past, I've had a Page_Load event and if not Postback, I setup a
    datareader and read the values from the datareader and populate the
    label/literal/textbox controls.

    But I was thinking there must be a way to utilize the SqlDatasource object
    and do the same thing (thus saving having to write all that SP calling code
    in the Page_Load).

    Thanks,
    Brian


  • =?Utf-8?B?TWFuaXNo?=

    #2
    RE: Databind a Label (or Literal), proper way?

    Hi Brian,

    I think you can try the following code to bind your Label control to a
    SqlDataSource.

    Dim dv As DataView =
    CType(SqlDataSo urce1.Select(Da taSourceSelectA rguments.Empty) , DataView)
    Dim dr As DataRowView = dv.Item(1)
    Me.Label1.Text = dr.Item(0)

    Regards,
    Manish
    MESCIUS USA Inc. has JavaScript and .NET UI controls, datagrids, reporting solutions, spreadsheets, document APIs and more to take your applications further.



    "Brian Simmons" wrote:
    I'll try to keep this short & sweet and hopefully get the direction I'm
    looking for.
    >
    I'll drop a SqlDatasource onto a webform. Configure it to use a stored
    proc, perhaps have the parameters be QueryString parms or Session variables,
    whatever the situation calls for.
    >
    The Stored Proc will return one row of data, let's say FirstName & LastName,
    John Smith.
    >
    I drop a Label (or Literal) onto the webform.
    >
    I would like the Label's Text property to be set to FirstName.
    >
    What/where is the proper way to hook this up?
    >
    In the past, I've had a Page_Load event and if not Postback, I setup a
    datareader and read the values from the datareader and populate the
    label/literal/textbox controls.
    >
    But I was thinking there must be a way to utilize the SqlDatasource object
    and do the same thing (thus saving having to write all that SP calling code
    in the Page_Load).
    >
    Thanks,
    Brian
    >
    >
    >

    Comment

    Working...