Recidivist
New Member
<BR>I have a datalist that is populated by a database table.<BR>Hardware Table<BR> - HardwareID<BR> - HardwareTitle<BR>A textbox and label will be displayed for every item. Techs will use this form to enter how many of a certain hardware item they used on a job. They will enter the number used into the textbox.<BR><BR><asp:datalist id="HardwareList" runat="server" cssclass="normal" DataKeyField="HardwareID" OnItemCreated="ListItemCreated" repeatlayout="Table" repeatcolumns="5" repeatdirection="Horizontal" gridlines="None"><BR><itemtemplate><BR><table width="100%" border="0" cellspacing="2" cellpadding="0"><BR> <tr><BR> <td width="2"><BR> <asp:textbox id="HardwareItem" runat="server" cssclass="FormFields" Columns="3"></asp:textbox><BR> </td><BR> <td align="left"><BR> <span class="normal"><BR> <%#DataBinder.Eval(Container.DataItem,"HardwareTitle")%><BR> </span><BR> </td><BR></tr><BR></table><BR></itemtemplate><BR></asp:datalist><BR><BR>Everytime an item is created this sub is called. It adds the Attribute "HardwareID" to the textbox and sets the value.<BR><BR> Sub ListItemCreated(ByVal sender As Object, ByVal e As DataListItemEventArgs) Handles HardwareList.ItemCreated<BR> If Not Page.IsPostBack Then<BR> If (e.Item.ItemType = ListItemType.Item) Or (e.Item.ItemType = ListItemType.AlternatingItem) Then<BR> CType(e.Item.FindControl("HardwareItem"), TextBox).Attributes.Add("HardwareID", e.Item.DataItem("HardwareID"))<BR> End If<BR> End If<BR> End Sub<BR><BR>When the form is submitted, I will need to get the number that was entered into the textbox and the value of the HardwareID attribute. The sub below will loop through the items inside the HardwareList datalist and should get the HardwareID attribute, but the value of this attribute is always blank. After the page is loaded into ie I can view source and see that the attribute is there with the correct value, but when submitted it's not. I think that I might be getting the values from preload and not from the post.<BR><BR> Sub SubmitTimeSheet_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles SubmitTimeSheet.Click<BR><BR> Dim we As DataList = CType(Page.FindControl("HardwareList"), DataList)<BR> Dim s As String<BR> Dim item As DataListItem<BR> For Each item In we.Items<BR> Dim c As Control = item.FindControl("HardwareItem")<BR> s = CType(c, TextBox).Attributes.Item("HardwareID")<BR> Next<BR>end sub<BR><BR>This is a little complex, so if anything is not clear I can try to explain better.<BR>Thanks,<BR>JonHi Jon,<BR><BR> I think what you need is to refer to your control as "HardwareList:HardwareItem". I typically use datagrids instead of lists, but I bet that part is similar.<BR><BR>Deanna