Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations John Tel on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

More Datalist Help... 1

Status
Not open for further replies.

1Data

MIS
Sep 30, 2005
66
US
Two days ago i asked for some help with a Datalist problem that was resolved thanks to Jim and Co. It was solved using the ItemDataBound Event. I have a new problem, however, I was wondering if anyone can offer some suggestions.

I would like to extract a DataItem in the Items Template that is not assigned to a control in my HTML. I know how to do this through an assignment to a control but how can I do it if it's not assigned to anything?

Here is the HTML Code:

<ItemTemplate>
<asp:LinkButton id="Linkbutton3" runat="server" Text="View" CommandName="edit"></asp:LinkButton><I>&nbsp;
Org: <%# DataBinder.Eval(Container.DataItem, "school")%>
&nbsp;-&nbsp;<%# DataBinder.Eval(Container.DataItem, "school_name")%>&nbsp;&nbsp;
Rec. Date: &nbsp;<%# DataBinder.Eval(Container.DataItem, "rec_date")%>&nbsp;&nbsp;&nbsp;Status:&nbsp;
<%# status(DataBinder.Eval(Container.DataItem, "status"))%>
</I>
</ItemTemplate>

Here is my code behind so far:
Private Sub Datalist2_ItemDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.DataListItemEventArgs) Handles Datalist2.ItemDataBound
If e.Item.ItemType = ListItemType.Item Then
Dim txtStatus As TextBox = e.Item.FindControl("Textbox23")
End If
End Sub

Jim, Thanks again for your help earlier in the week that was perfect.

 
No problem glad to help.

I am a little confused on what you want to do here. I see you have a linkbutton in the itemtemplate column. Are you trying to get the text assigned to it?

Jim
 
Jim,

I figured it out, here is what I am using..then I will explain...

Private Sub Datalist2_ItemDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.DataListItemEventArgs) Handles Datalist2.ItemDataBound

Dim MyStatus As String
If e.Item.ItemType = ListItemType.Item Then
MyStatus = e.Item.DataItem("status")
End IF

With the code you gave me before I had to create a new instance of a text box..the original question there is no text box so I didn't know how to obtain the value of this object in my HTML. This "Status" value is just being showed in my app..it's not being attached to any control(textbox etc...) I played around with it and used the DataItem Method and it works...within my Item Template. Basically, stepped through your code and modified it with ListItem.Item because that's where this value is and then used to the DataItem Method to extract the value..
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top