11/26/2024 2:24:38 AM
|
|
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!
Forum to discuss building external web applications for SalesLogix. View the code of conduct for posting guidelines.
|
|
|
|
Automating numbered controls in .NET
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? |
|
|
|
Re: Automating numbered controls in .NET
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? |
|
|
|
Re: Automating numbered controls in .NET
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. |
|
|
| |
|
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!
|
|
|
|
|
|
|
|