473,386 Members | 1,841 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

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 3144
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: DelphiBlue | last post by:
I have a Nested Datagrid that is using a data relations to tie the parent child datagrids together. All is working well with the display but I am having some issues trying to sort the child...
4
by: Das | last post by:
Hi, I have made an application in ASP.net with C#. The application works fine with localhost. I have uploaded the site. I'm using web user controls in the form. but some of the button do not work...
1
by: bill yeager | last post by:
I have a datagrid control within a datalist control. When I try and do a "Find" on the control, the object comes back with nothing and then my pgm crashes. I am 100% sure that my datagird inside...
8
by: Nevyn Twyll | last post by:
I have a multi-level datalist setup: DataList1 DataList2 MyGrid I have columns explicitly defined for the grid in the html. Sometimes, On the initial Load() of the Page, I want to add extra...
9
by: tshad | last post by:
How do I find (and set) a couple of labels in the Footer after a DataGrid is filled? I have a bunch of DataGrids that get displayed nested inside a DataList. The datagrid looks like: ...
1
by: Roy | last post by:
How is it done? BTW, I'm reposting this here, as the datagrid newsgroup appears functionally comatose... I have a nested datagrid setup. When one updates the child grid using edit, it also...
0
by: I am Sam | last post by:
Ok whats wrong with my toolbar? When I debug I don't get an error message and the databinding is working correctly but the toolbar itself and the <iewc:ToolbarDropDownlist /> control isn't showing...
2
by: nulldevice | last post by:
I've got a datagrid with some nested controls, created at design-time. The controls themselves have no databound values. After a few other operations on the page (selecting a few parameters,...
5
by: sck10 | last post by:
Hello, I am using the code below to set the values of a DetailsView template field using FindControl. My question is how would you find a control if its a Boundfield control? For example,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.