Need help finding control.

Results 1 to 2 of 2

Thread: Need help finding control.

  1. #1
    Join Date
    Dec 1969

    Default Need help finding control.

    &nbsp;<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>&#060;asp:datalist id="HardwareList" runat="server" cssclass="normal" DataKeyField="HardwareID" OnItemCreated="ListItemCreated" repeatlayout="Table" repeatcolumns="5" repeatdirection="Horizontal" gridlines="None"&#062;<BR>&#060;itemtemplate&#062; <BR>&#060;table width="100%" border="0" cellspacing="2" cellpadding="0"&#062;<BR> &#060;tr&#062;<BR> &#060;td width="2"&#062;<BR> &#060;asp:textbox id="HardwareItem" runat="server" cssclass="FormFields" Columns="3"&#062;&#060;/asp:textbox&#062;<BR> &#060;/td&#062;<BR> &#060;td align="left"&#062;<BR> &#060;span class="normal"&#062;<BR> &#060;%#DataBinder.Eval(Container.DataItem,"Hardwa reTitle")%&#062;<BR> &#060;/span&#062;<BR> &#060;/td&#062;<BR>&#060;/tr&#062;<BR>&#060;/table&#062;<BR>&#060;/itemtemplate&#062;<BR>&#060;/asp:datalist&#062;<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&#039;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>Jon

  2. #2
    Join Date
    Dec 1969

    Default RE: Need help finding control.

    Hi 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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts