Find Control in a nested DataGrid

J

Josh

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
 
T

Thomas Dodds

did you try?

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

[Find the control in the Row (assuming you have a uniquely named control -
which it appears to be so) ...]
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,226
Members
46,815
Latest member
treekmostly22

Latest Threads

Top