kriskramer
asked on
Populating a Repeater with a DataReader/DataSet
This should probably be an easy question but I can't seem to figure it out. I'm making a series of user controls that show customer/company information, and I set up the following Dataset and repeater for testing. The XML file is a temp replacement for the actual database call, and it holds ContactType, FirstName, LastName and Phone for each contact, and I can get the information to display just fine.
Dim test As New DataSet 'for testing
test.ReadXml(MapPath("../x mlfile1.xm l"))
Repeater1.DataSource = test 'drResults
Repeater1.DataBind()
<ItemTemplate>
<tr>
<td><%# DataBinder.Eval(Container. DataItem, "sContactType") %></td>
<td><%# DataBinder.Eval(Container. DataItem, "FirstName") & " " & databinder.eval(container. dataitem, "LastName") %></td>
<td><%# DataBinder.Eval(Container. DataItem, "PhoneNumber") %></td>
</tr>
</ItemTemplate>
The problem is, the ContactType is stored as a number, and I want to associate that number with an actual text value. Without changing how the data is retrieved, how would I change the number to the actual text value of the contact type in this situation?
Dim test As New DataSet 'for testing
test.ReadXml(MapPath("../x
Repeater1.DataSource = test 'drResults
Repeater1.DataBind()
<ItemTemplate>
<tr>
<td><%# DataBinder.Eval(Container.
<td><%# DataBinder.Eval(Container.
<td><%# DataBinder.Eval(Container.
</tr>
</ItemTemplate>
The problem is, the ContactType is stored as a number, and I want to associate that number with an actual text value. Without changing how the data is retrieved, how would I change the number to the actual text value of the contact type in this situation?
ASKER
Actually, I'm not trying to get the number as a string, I'm trying to figure out where I can put in code to change the number to text.
For example: If i have 3 contact types, Primary Contact, Additional Contact, Site Manager. Those are saved as numbers, either 1, 2 or 3 in the database, and those numbers will be returned and displayed in the repeater. I want the text to be displayed instead, though, and I don't know where I can go to put in code to make that change.
I basically want to do a
Select Case X
Case 1: X = "Primary Contact"
Case 2: X = "Additional Contact"
Case 3: X = "Site Manager"
End Select
I just need to know where I would put this at, and what X would be.
For example: If i have 3 contact types, Primary Contact, Additional Contact, Site Manager. Those are saved as numbers, either 1, 2 or 3 in the database, and those numbers will be returned and displayed in the repeater. I want the text to be displayed instead, though, and I don't know where I can go to put in code to make that change.
I basically want to do a
Select Case X
Case 1: X = "Primary Contact"
Case 2: X = "Additional Contact"
Case 3: X = "Site Manager"
End Select
I just need to know where I would put this at, and what X would be.
Use the onItemDataBound event
Here is an example of the onItemDataBound use:
http://aspnet.4guysfromrolla.com/articles/090402-1.2.aspx
Here is an example of the onItemDataBound use:
http://aspnet.4guysfromrolla.com/articles/090402-1.2.aspx
ASKER
I know about the onItemCreated and onItemDataBound events, but I don't know how to reference or change the actual data item. The example above uses a datalist, the .cells collection isn't available in a repeater.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
or
<td><%# Container.DataItem("sConta