Finding a control in a Nested DataGrid

Tech Tip: Click here to run a free scan for Windows Errors and optimize PC performance

From: Josh (josh_at_rb.com.auREMOVETOEMAIL)
Date: 08/31/04


Date: Tue, 31 Aug 2004 14:12:35 +1000

Hi Guys,

I have been stuck on this problem for several days now, i have a set of
nested datagrids. Inside the second datagrid i have a dropdown list, a
textbox and a label. I want the textbox to update the label with the value
of the dropdown list * the text box quantity. I am using an onTextChaged
even on the textbox, the problem i have is that i can not find the lblPrice
control.

Thanks for the help,
Josh

INLINE CODE:
<asp:datagrid id="dgCategories" runat="server" AutoGenerateColumns="False"
VerticalAlign="Top"
      HorizontalAlign="Center" border="0" Font-Names="Verdana"
CellPadding="4" ItemStyle-CssClass="p"
      headerStyle-CssClass="p" Width="95%">
      <ItemStyle CssClass="tabletext"></ItemStyle>
      <HeaderStyle CssClass="header"></HeaderStyle>
      <Columns>
       <asp:BoundColumn DataField="styleName"
HeaderText="Category"></asp:BoundColumn>
       <asp:TemplateColumn HeaderText="">
        <ItemTemplate>
         <asp:DataGrid id="dgProducts" ShowHeader=False runat="server"
AutoGenerateColumns="False" DataSource='<%# GetProducts
(container.dataitem("catID"))%>' Width="100%" headerStyle-CssClass="p"
ItemStyle-CssClass="p" BorderWidth=0 OnCancelCommand="dgProducts_Cancel"
OnUpdateCommand="dgProducts_Update" OnEditCommand="dgProducts_Edit"
OnItemDataBound="dgProducts_DataBound" DataKeyField="styleID">
          <ItemStyle CssClass="tabletextinner"></ItemStyle>
          <Columns>
           <asp:BoundColumn DataField="styleID" HeaderText="Name"
Visible="false"></asp:BoundColumn>
           <asp:BoundColumn DataField="styleName" HeaderText="Name"
Visible="false"></asp:BoundColumn>
           <asp:TemplateColumn>
            <ItemTemplate>
             Style:
             <asp:DropDownList id="ddlSize"
runat="server"></asp:DropDownList>
            </ItemTemplate>
           </asp:TemplateColumn>
           <asp:TemplateColumn>
            <ItemTemplate>
             Quantity:
             <asp:TextBox id="txtQuantity" runat="server" AutoPostBack=true
OnTextChanged="txtQuantity_TextChanged" Width="70"></asp:TextBox>
            </ItemTemplate>
           </asp:TemplateColumn>
           <asp:TemplateColumn>
            <ItemTemplate>
             Price:
             <asp:Label id="lblPrice" runat="server"></asp:Label>
            </ItemTemplate>
           </asp:TemplateColumn>
          </Columns>
         </asp:DataGrid>
        </ItemTemplate>
       </asp:TemplateColumn>
      </Columns>
     </asp:datagrid>

CODE BEHIND
Function GetProducts(ByVal x As String)
Dim params As String() = {"@catID", x}

Dim dsClients As DataSet = database.SPFill("sp_getProductsInCat", "clients",
params)

Response.Write("catID = " & x)

Return dsClients.Tables(0)

End Function

Sub txtQuantity_TextChanged(ByVal sender As Object, ByVal e As EventArgs)

Dim price As System.Web.UI.WebControls.Label

' Find control on page.

Dim i As Integer = 0

While i < 20

Try

price = CType(dgProducts.Items(i).Cells(4).FindControl("lblPrice"),
System.Web.UI.WebControls.Label)

price.Text = "MOFO"

Catch ex As Exception

End Try

i = i + 1

End While

End Sub

Sub dgProducts_DataBound(ByVal obj As Object, ByVal e As
System.Web.UI.WebControls.DataGridItemEventArgs)

Dim size As System.Web.UI.WebControls.DropDownList

Dim shape As System.Web.UI.WebControls.DropDownList

If e.Item.ItemType = ListItemType.Item Or e.Item.ItemType =
ListItemType.AlternatingItem Or e.Item.ItemType = ListItemType.EditItem Then

size = CType(e.Item.Cells(2).Controls(1),
System.Web.UI.WebControls.DropDownList)

'set the drop down lists witht eh apprioprtite infomation

Dim params As String() = {"@styleID", e.Item.Cells(0).Text}

Dim dsSizesShapes As DataSet = database.SPFill("sp_getProductsForStyle",
"tbl_products", params)

Dim dr As DataRow

For Each dr In dsSizesShapes.Tables(0).Rows

size.Items.Add(New ListItem(convertToWeight(dr("productSize")) & " \ " &
dr("productShape"), dr("productPrice")))

Next

End If

End Sub



Relevant Pages

  • Find Control in a nested DataGrid
    ... nested datagrids. ... I want the textbox to update the label with the value ... Dim params As String= ... Dim price As System.Web.UI.WebControls.Label ...
    (microsoft.public.dotnet.framework.aspnet)
  • =?Utf-8?Q?RE:_unbekannte_Textbox_l=C3=B6schen?=
    ... welche davon in der betreffenden Zeile in Spalte B liegt. ... wird aber nur diejenige TextBox, deren Adresse mit der der aktiven Zeile ... Dim tbElement As TextBox ... Dim txtBox As Shape, TXTBoxName ...
    (microsoft.public.de.excel)
  • Re: How to get specific data from .txt file in VB6?
    ... Index of the TextBox corresponding to the Software ... how to make use of the control array to do what you originally asked... ... Dim FF As Long ... Dim TotalFile As String ...
    (microsoft.public.vb.general.discussion)
  • Re: selectedvalue postback problem
    ... have to recreate the dropdown list first, and they it'll take care of ... ByVal sender As Object, _ ... Dim row As DataRow = CType ... Dim textBox As TextBox = .FindControl ...
    (microsoft.public.dotnet.framework.aspnet)
  • Re: selectedvalue postback problem
    ... have to recreate the dropdown list first, and they it'll take care of ... ByVal sender As Object, _ ... Dim row As DataRow = CType ... Dim textBox As TextBox = .FindControl ...
    (microsoft.public.dotnet.framework.aspnet)