Home | Forums | Contact | Search | Syndication  
 
 [login] [create account]   Sunday, May 5, 2024 
 
slxdeveloper.com Community Forums  
   
The Forums on slxdeveloper.com are now retired. The forum archive will remain available for the time being. Thank you for your participation on slxdeveloper.com!
 Web Forums - ASP/ASP.NET/Web Services/Other
Forum to discuss building external web applications for SalesLogix. View the code of conduct for posting guidelines.
Forums RSS Feed


 Back to Forum List | Back to ASP/ASP.NET/Web Services/Other | New ThreadView:  Search:  
 Author  Thread: Automating numbered controls in .NET
David Nunnally
Posts: 206
 
Automating numbered controls in .NETYour last visit to this thread was on 1/1/1970 12:00:00 AM
Posted: 03 Jan 07 11:26 AM
fiogf49gjkf0d
Another newbie question here. I have a web app with duplicated options. For example, I have three dropdownlists (ddlOption1, ddlOption2, ddlOption3). Each option (if selected) must be saved as a seperate record in my custom SLX table. At present I am using three save routines and specifying Me.ddlOption1.text in the first, Me.ddlOption2.text in the second, etc. Is there a way that I can automate this into one save routine and loop through saving all values associated with option1 then 2 etc?
[Reply][Quote]
Ryan Farley
Posts: 2265
slxdeveloper.com Site Administrator
Top 10 forum poster: 2265 posts
 
Re: Automating numbered controls in .NETYour last visit to this thread was on 1/1/1970 12:00:00 AM
Posted: 05 Jan 07 10:59 AM
fiogf49gjkf0d
Really, I'd keep it simple. If all you have are the three options, it's pretty simple to just do the update three times (put the actual update code somewhere in a function so you just have to call the function three times and pass the control to use for the update).

If you had a variable number of controls, you could loop through them in a number of different ways. An easy way would be to use FindControl. You use FindControl like this:

TextBox t = (TextBox)Page.FindControl("txtMyTextBox");
//or
DropDownList ddl = (DropDownList)Panel1.FindControl("ddlOption1");


Notice the object that FindControl is being used against. FindControl will look for the control in that host object. So if you call it on a Page, it will only look on the page - if your control is in some other container on the page it won't find it. You have to call FindControl on the container. Or you could make it a recursive call to find the control by starting with the page and working down.

If all your controls are in the same container, we'll assume "Panel1" for now, your code would look like this:

for (int i=1; i<4; i++)
{
DropDownList ddl = Panel1.FindControl("ddlOption" + i.ToString());
updateValueOrSomething(ddl.Text);
}


See what I mean?
[Reply][Quote]
David Nunnally
Posts: 206
 
Re: Automating numbered controls in .NETYour last visit to this thread was on 1/1/1970 12:00:00 AM
Posted: 05 Jan 07 11:11 AM
fiogf49gjkf0d
DropDownList ddl = Panel1.FindControl("ddlOption" + i.ToString()) was exactly what I needed. No I have a great deal more than three. I just wanted to keep my example simple. Basically I have 9 controls grouped for one '?action?'( - for lack of better word) that all end in 1. Then then next set of nine end in 2 and so on. There are a variable number of these groups depending on the product/family/pricegroup/etc. Maybe as little as three and as many as 15. Although it is not too difficult to cut-n-paste the code during development; mods laters it can be a pain to support with all the duplication. This will greatly cleanup and simplify the code.
[Reply][Quote]
virtam
Posts: 43
 
Re: Automating numbered controls in .NETYour last visit to this thread was on 1/1/1970 12:00:00 AM
Posted: 30 May 08 2:47 PM
and I would like to retrieve the names of objects that are in the textbox form?

must list the objects on a table.
[Reply][Quote]
 Page 1 of 1 
  You can subscribe to receive a daily forum digest in your user profile. View the site code of conduct for posting guidelines.

   Forum RSS Feed - Subscribe to the forum RSS feed to keep on top of the latest forum activity!
 

 
 slxdeveloper.com is brought to you courtesy of Ryan Farley & Customer FX Corporation.
 This site, and all contents herein, are Copyright © 2024 Customer FX Corporation. The information and opinions expressed here are not endorsed by Sage Software.

code of conduct | Subscribe to the slxdeveloper.com Latest Article RSS feed
   
 
page cache (param): 5/5/2024 12:10:03 PM