468,783 Members | 1,616 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,783 developers. It's quick & easy.

Find Control in a nested DataGrid

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("lb lPrice"),
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
Nov 18 '05 #1
2 2919
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) ...]

"Josh" <jo**@rb.com.auREMOVETOEMAIL> wrote in message
news:un**************@TK2MSFTNGP11.phx.gbl...
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("lb lPrice"),
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

Nov 18 '05 #2
Hi Josh:

this article has C# code but it gives some more insight into using
FindControl:

http://odetocode.com/Articles/116.aspx

--
Scott
http://www.OdeToCode.com

On Tue, 31 Aug 2004 13:38:51 +1000, "Josh"
<jo**@rb.com.auREMOVETOEMAIL> wrote:
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.


Nov 18 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

4 posts views Thread by Das | last post: by
1 post views Thread by bill yeager | last post: by
9 posts views Thread by tshad | last post: by
reply views Thread by I am Sam | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by zhoujie | last post: by
2 posts views Thread by Marin | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.