By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
457,954 Members | 1,248 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 457,954 IT Pros & Developers. It's quick & easy.

Dynamic Controls & Values

P: n/a
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
Share this Question
Share on Google+
2 Replies


P: n/a
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

P: n/a
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 discussion thread is closed

Replies have been disabled for this discussion.