473,387 Members | 1,693 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,387 software developers and data experts.

Dynamic Controls & Values

Hello all,

I am faced with some logic that I am unsure how to handle. Imagine that
I am running a WMI query and I am outputting the data into a
dynamically created ASP table control. Here is my code that does this.
I have left out the portion that connects to my server and the query,
but this should be enough to show what I am doing. Basically it is a
web page that queries SMS for clients in a certain collection, then
outputs the name value and offers a drop down list that has choices for
existing collections that the name can be moved into. I have a seperate
function that does this for me.

Dim objWQL As New WqlObjectQuery(strWQL)
Dim myObjectSearcher As New ManagementObjectSearcher(scope,
objWQL)
Dim myObjectCollection As
System.Management.ManagementObjectCollection
Dim myObject As System.Management.ManagementObject
myObjectCollection = myObjectSearcher.Get()

For Each myObject In myObjectCollection

myClientList.Add(myObject.GetPropertyValue("Name") .ToString())
Next
Dim myCounter As Integer = 1
For Each myClient As String In myClientList
Dim myTableRow As New TableRow
Dim myCell1 As New TableCell
Dim myCell2 As New TableCell
Dim ddl As New DropDownList

ddl.Width = 100
ddl.Items.Add("1")
ddl.Items.Add("2")
ddl.Items.Add("3")

myCell1.BackColor = Drawing.Color.Red
myCell2.BackColor = Drawing.Color.Blue
Table1.Rows.Add(myTableRow)
Table1.Rows(myCounter).Cells.Add(myCell1)
Table1.Rows(myCounter).Cells.Add(myCell2)
myCell1.Text = myClient.ToString
myCell2.Controls.Add(ddl)
myCounter = myCounter + 1
Next

So here is my question. I am only returning one value on each iteration
of the for each loop, and that is the name property. I am outputting
this name property in the first cell of a table row, and a am
outputting a drop down list into the second cell of a table. I am
confused as to how I can wire the value in the drop down list to the
name value in cell 1. For example, imagine that I have 4 rows in my
table, each one containing a server name in cell 1, and a drop down
list in cell 2. I also have a submit button after my table is closed.
When I click submit, I am attempting to iterate through each row in the
table, get the server name from cell 1 and the corresponding value from
the drop down in cell 2. I then use these 2 values to feed a function
that does something with the values. I guess I am really having trouble
associating the drop down with the appropriate server name in cell 1 of
each row and then getting the data on submit. So in a nutshell, there
could be multiple rows in the table, each row will have a different
server name (returned from the WMI query) in cell 1 and a drop down in
cell 2. On submit, I have to gather the data from each row, process it,
then move onto the next row until there are no rows left. It is
extremely important that I can get the value from the drop down list in
cell 2 and associate with the server name in each row. Each row could
have unique values in the drop down list. I am unsure how to do this or
if it is even possible. If someone can assist, it would be greatly
appreciated. Thank you in advance for any help that can be offered.

Jim Gregg

Oct 18 '06 #1
2 1775
Jim,

All is possible! I think what you're suffering from is a ViewState
problem with the dynamically created table. That information isn't
readily available on post back in asp.net 1.1, and I've only used
gridviews in .net 2.0...so I can only assume that is the case w/ 2.0 as
well.

I would solve this problem by approaching it a tad differently. Here is
my solution for this:

Solution #1 (of infinite others I'm sure):

1. ) Fill dataset with 2 result sets. 1 for servers, the other with
child data for those clients.
2. ) Create DataRelation between 2 tables in result set.
3. ) Create a repeater in aspx page and bind results of table[0] to it.
4. ) In the item template of the repeater have a datagrid (gridview in
2.0), binding it to the .GetChildRows of the relationship.
5. ) Implement ItemCommand utilizing CommandName and CommandArgument. I
always stuff my unique identifier (in your case, serverName) into the
CommandArgument so I know exactly which piece of data I'm working with.

Let me know if any of this needs explaining.

Good luck!

~Brenton MCSD.NET

Jim Gregg wrote:
Hello all,

I am faced with some logic that I am unsure how to handle. Imagine that
I am running a WMI query and I am outputting the data into a
dynamically created ASP table control. Here is my code that does this.
I have left out the portion that connects to my server and the query,
but this should be enough to show what I am doing. Basically it is a
web page that queries SMS for clients in a certain collection, then
outputs the name value and offers a drop down list that has choices for
existing collections that the name can be moved into. I have a seperate
function that does this for me.

Dim objWQL As New WqlObjectQuery(strWQL)
Dim myObjectSearcher As New ManagementObjectSearcher(scope,
objWQL)
Dim myObjectCollection As
System.Management.ManagementObjectCollection
Dim myObject As System.Management.ManagementObject
myObjectCollection = myObjectSearcher.Get()

For Each myObject In myObjectCollection

myClientList.Add(myObject.GetPropertyValue("Name") .ToString())
Next
Dim myCounter As Integer = 1
For Each myClient As String In myClientList
Dim myTableRow As New TableRow
Dim myCell1 As New TableCell
Dim myCell2 As New TableCell
Dim ddl As New DropDownList

ddl.Width = 100
ddl.Items.Add("1")
ddl.Items.Add("2")
ddl.Items.Add("3")

myCell1.BackColor = Drawing.Color.Red
myCell2.BackColor = Drawing.Color.Blue
Table1.Rows.Add(myTableRow)
Table1.Rows(myCounter).Cells.Add(myCell1)
Table1.Rows(myCounter).Cells.Add(myCell2)
myCell1.Text = myClient.ToString
myCell2.Controls.Add(ddl)
myCounter = myCounter + 1
Next

So here is my question. I am only returning one value on each iteration
of the for each loop, and that is the name property. I am outputting
this name property in the first cell of a table row, and a am
outputting a drop down list into the second cell of a table. I am
confused as to how I can wire the value in the drop down list to the
name value in cell 1. For example, imagine that I have 4 rows in my
table, each one containing a server name in cell 1, and a drop down
list in cell 2. I also have a submit button after my table is closed.
When I click submit, I am attempting to iterate through each row in the
table, get the server name from cell 1 and the corresponding value from
the drop down in cell 2. I then use these 2 values to feed a function
that does something with the values. I guess I am really having trouble
associating the drop down with the appropriate server name in cell 1 of
each row and then getting the data on submit. So in a nutshell, there
could be multiple rows in the table, each row will have a different
server name (returned from the WMI query) in cell 1 and a drop down in
cell 2. On submit, I have to gather the data from each row, process it,
then move onto the next row until there are no rows left. It is
extremely important that I can get the value from the drop down list in
cell 2 and associate with the server name in each row. Each row could
have unique values in the drop down list. I am unsure how to do this or
if it is even possible. If someone can assist, it would be greatly
appreciated. Thank you in advance for any help that can be offered.

Jim Gregg
Oct 18 '06 #2
If you have an example of this, it would be much appreciated. Also, I
was not sure if it was possible to fill a data set with the results of
a WMI query. I guess I just always assumed that a dataset was database
related only. Let me know.

Jim Gregg

Superman wrote:
Jim,

All is possible! I think what you're suffering from is a ViewState
problem with the dynamically created table. That information isn't
readily available on post back in asp.net 1.1, and I've only used
gridviews in .net 2.0...so I can only assume that is the case w/ 2.0 as
well.

I would solve this problem by approaching it a tad differently. Here is
my solution for this:

Solution #1 (of infinite others I'm sure):

1. ) Fill dataset with 2 result sets. 1 for servers, the other with
child data for those clients.
2. ) Create DataRelation between 2 tables in result set.
3. ) Create a repeater in aspx page and bind results of table[0] to it.
4. ) In the item template of the repeater have a datagrid (gridview in
2.0), binding it to the .GetChildRows of the relationship.
5. ) Implement ItemCommand utilizing CommandName and CommandArgument. I
always stuff my unique identifier (in your case, serverName) into the
CommandArgument so I know exactly which piece of data I'm working with.

Let me know if any of this needs explaining.

Good luck!

~Brenton MCSD.NET

Jim Gregg wrote:
Hello all,

I am faced with some logic that I am unsure how to handle. Imagine that
I am running a WMI query and I am outputting the data into a
dynamically created ASP table control. Here is my code that does this.
I have left out the portion that connects to my server and the query,
but this should be enough to show what I am doing. Basically it is a
web page that queries SMS for clients in a certain collection, then
outputs the name value and offers a drop down list that has choices for
existing collections that the name can be moved into. I have a seperate
function that does this for me.

Dim objWQL As New WqlObjectQuery(strWQL)
Dim myObjectSearcher As New ManagementObjectSearcher(scope,
objWQL)
Dim myObjectCollection As
System.Management.ManagementObjectCollection
Dim myObject As System.Management.ManagementObject
myObjectCollection = myObjectSearcher.Get()

For Each myObject In myObjectCollection

myClientList.Add(myObject.GetPropertyValue("Name") .ToString())
Next
Dim myCounter As Integer = 1
For Each myClient As String In myClientList
Dim myTableRow As New TableRow
Dim myCell1 As New TableCell
Dim myCell2 As New TableCell
Dim ddl As New DropDownList

ddl.Width = 100
ddl.Items.Add("1")
ddl.Items.Add("2")
ddl.Items.Add("3")

myCell1.BackColor = Drawing.Color.Red
myCell2.BackColor = Drawing.Color.Blue
Table1.Rows.Add(myTableRow)
Table1.Rows(myCounter).Cells.Add(myCell1)
Table1.Rows(myCounter).Cells.Add(myCell2)
myCell1.Text = myClient.ToString
myCell2.Controls.Add(ddl)
myCounter = myCounter + 1
Next

So here is my question. I am only returning one value on each iteration
of the for each loop, and that is the name property. I am outputting
this name property in the first cell of a table row, and a am
outputting a drop down list into the second cell of a table. I am
confused as to how I can wire the value in the drop down list to the
name value in cell 1. For example, imagine that I have 4 rows in my
table, each one containing a server name in cell 1, and a drop down
list in cell 2. I also have a submit button after my table is closed.
When I click submit, I am attempting to iterate through each row in the
table, get the server name from cell 1 and the corresponding value from
the drop down in cell 2. I then use these 2 values to feed a function
that does something with the values. I guess I am really having trouble
associating the drop down with the appropriate server name in cell 1 of
each row and then getting the data on submit. So in a nutshell, there
could be multiple rows in the table, each row will have a different
server name (returned from the WMI query) in cell 1 and a drop down in
cell 2. On submit, I have to gather the data from each row, process it,
then move onto the next row until there are no rows left. It is
extremely important that I can get the value from the drop down list in
cell 2 and associate with the server name in each row. Each row could
have unique values in the drop down list. I am unsure how to do this or
if it is even possible. If someone can assist, it would be greatly
appreciated. Thank you in advance for any help that can be offered.

Jim Gregg
Oct 18 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: K | last post by:
I have found a script online that I want to use (I am new to PHP). It creates dynamic images based on the text that you pass it. However, no matter how I try, I can't get anything other than a...
1
by: Nathan Bloomfield | last post by:
Does anyone know if there is any documentation which relates to Access2k + ? or can anyone help adjust the code? I am having trouble converting the DAO references. TITLE :INF: How to...
1
by: hybrid | last post by:
I have problems in understanding the behavior of the events triggered by dynamically created controls over a webform. Could you help me? In a webform, I have a static PlaceHolder PH containing...
1
by: Scott Schluer | last post by:
Hello, I've got myself a small problem and I'm hoping someone can help. I have a DataList called dlProducts (displays products from a database). Within the <ItemTemplate> container of the...
2
by: Ben Amada | last post by:
I'm a little confused about in what Event should I add dynamic controls and in what Event should I retrieve the value of a dynamic control on postback. I've found that adding dynamic controls in...
1
by: Kevin R | last post by:
This is one of the weirdest problems I have ever run into. I have had to trim down a bunch of code to give a sample that is more easily readable by those who will view this. Here is the problem:...
4
Frinavale
by: Frinavale | last post by:
Introduction Sometimes, when developing web applications, we need to be able to dynamically load controls based on user selections. The following article describes a simple scenario where TextBox...
2
by: englishman69 | last post by:
Hello, I have been banging my head against this one for a while... Searches online have revealed many different proposals for correcting my issue but none that I can follow! My basic situation...
5
by: Hans Kesting | last post by:
Hi, Is there good information about the asp.net page lifecycle in combination with dynamically loaded controls? Or on "how to build dynamic controls"? I keep hitting problems where values are...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
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
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.