|
 |
aspx thread: Web User Control: databinding, getting the data...
Message #1 by "Chris Kersey" <ckersey@m...> on Thu, 23 May 2002 15:03:10 -0700
|
|
I created a Web User control that is derived from the WebControl and I want
to be able to render my control from multiple rows out of the database.
Question is, if I am able to bind my control to a dataset via the
WebControl's inherited Bind method and if so how do I get at the data that
was bound?
I wanna do this...
protected override void Render(HtmlTextWriter output)
{
//I want to loop thru stuff.. foreach(string stuff in Dataset("eh"))
output.Write(stuff + "<BR>");
}
Thanks for any input you might have :)
Chris
Message #2 by "Subraya Hegde" <subrayah@i...> on Fri, 24 May 2002 10:45:24 +0530
|
|
Try to make use of this:
<%# DataBinder.Eval(Container.DataItem, "FieldName1") %>
<%# DataBinder.Eval(Container.DataItem, "FieldName2") %>
-HegdeS
Message #3 by Feduke Cntr Charles R <FedukeCR@m...> on Fri, 24 May 2002 08:43:54 -0400
|
|
Chris,
If you're binding a data set then are your inheriting from Repeater,
DataList, or DataGrid? If not, then you should; you can override or add a
new delegate to the event OnItemCreated and write your own logic there to
handle the display of items.
Otherwise, I think you're looking for something like the following:
// get your dataset, ds, with a table named "data" in it
DataTable dt = (DataTable)ds.Tables["data"];
foreach (DataRow row in dt.Select())
{
output.Write(row["last_name"].ToString() +
", " + row["first_name"].ToString() +
"<br>\n";
}
FYI, if you want to remain lightweight I'd recommend using a
*DataReader rather than the complete DataSet/DataTable. Unless you
specifically have a need for relationships, use a *DataReader (they are easy
to use!).
HTH,
- Chuck
-----Original Message-----
From: Chris Kersey [mailto:ckersey@m...]
Sent: Thursday, May 23, 2002 6:03 PM
To: ASP+
Subject: [aspx] Web User Control: databinding, getting the data...
I created a Web User control that is derived from the WebControl and I want
to be able to render my control from multiple rows out of the database.
Question is, if I am able to bind my control to a dataset via the
WebControl's inherited Bind method and if so how do I get at the data that
was bound?
I wanna do this...
protected override void Render(HtmlTextWriter output)
{
//I want to loop thru stuff.. foreach(string stuff in Dataset("eh"))
output.Write(stuff + "<BR>");
}
Thanks for any input you might have :)
Chris
|
|
 |