Link to home
Start Free TrialLog in
Avatar of sbornstein2
sbornstein2

asked on

ASP.Net/C# - Loop through Controls/Repeater

Hello all.  I have a Web form that has a repeater in it where I need to create a textbox per row.  Then in that row I will also have an ID field that will be a unique integer just text label.  The repeater is going to create a new control name and append a number character deal to the name/id of that textbox.  How can I loop through each textbox on the form and pull in the value with the ID?  I also have other textboxes on the form as well.  Any help all or example code.   Thanks
Avatar of nauman_ahmed
nauman_ahmed
Flag of United States of America image

What are you trying to do and why you want to put the id from the repeater?

-Nauman.
ASKER CERTIFIED SOLUTION
Avatar of rugu_16
rugu_16

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of sbornstein2
sbornstein2

ASKER

Its a little more trickier than that :).   What I need to do is I build up a datatable  because my resultset is not from one query etc.  or a view.  So I need to build a datatable in my C# code behind.  Then this is the real tricky part.  Based on a field which is called code I need to place a control, but that control can have different attributes depending on the code name.  Mostly its a MaxLength and text involved but in some cases its a TEXTAREA or in .Net it will be a scrollable textbox with rows.  Here is what I mean.  I have to check the code and then base on that code for that row create the control and properties such as:

                        [IF {[CODE_CD] == "AA"} {
                        <INPUT TYPE="TEXTBOX" ID="" NAME="FormItem[SHOW formitemcounter]" VALUE="" SIZE="15" MAXLENGTH="5">
                        <BR><FONT COLOR="RED" SIZE="-1"><I><B>NOTE:</B> You must limit your entry to 5 Characters</I></FONT>
                        }]
                        
                        [IF {[CODE_CD] == "BB"} {
                        <INPUT TYPE="TEXTBOX" ID="" NAME="FormItem[SHOW formitemcounter]" VALUE="" SIZE="15" MAXLENGTH="12">
                        <BR><FONT COLOR="RED" SIZE="-1"><I><B>NOTE:</B> You must limit your entry to 12 Characters</I></FONT>
                        }]
                        
                        [IF {[CODE_CD] == "CC"} {
                        <INPUT TYPE="TEXTBOX" ID="" NAME="FormItem[SHOW formitemcounter]" VALUE="" SIZE="15" MAXLENGTH="9">
                        <BR><FONT COLOR="RED" SIZE="-1"><I><B>NOTE:</B> You must limit your entry to 9 Characters</I></FONT>
                        }]
                        
                        [IF {[CODE_CD] == "DD"} {
                        <INPUT TYPE="TEXTBOX" ID="" NAME="FormItem[SHOW formitemcounter]" VALUE="" SIZE="15" MAXLENGTH="9">
                        <BR><FONT COLOR="RED" SIZE="-1"><I><B>NOTE:</B> You must limit your entry to 9 Characters</I></FONT>
                        }]
                        
                        [IF {[CODE_CD] == "EE"} {
                        <TEXTAREA ID="" NAME="FormItem[SHOW formitemcounter]" COLS="15" ROWS="6"></TEXTAREA>
                        <BR><FONT COLOR="RED" SIZE="-1"><I><B>NOTE:</B> You must limit your entry to 90 Characters</I></FONT>
                        }]
                        
                        [IF {[CODE_CD] == "FF"} {
                        <TEXTAREA ID="" NAME="FormItem[SHOW formitemcounter]" COLS="15" ROWS="10"></TEXTAREA>
                        <BR><FONT COLOR="RED" SIZE="-1"><I><B>NOTE:</B> You must limit your entry to 150 Characters</I></FONT>
                        }]
                        
                        [IF {[CODE_CD] == "GG"} {
                        <INPUT TYPE="TEXTBOX" ID="" NAME="FormItem[SHOW formitemcounter]" VALUE="" SIZE="15" MAXLENGTH="9">
                        <BR><FONT COLOR="RED" SIZE="-1"><I><B>NOTE:</B> You must limit your entry to 1 Character</I></FONT>
                        }]

Hope this makes sense.  So I have a datatable being built up I can bind to a grid but I dont think this will work as well as a repeater for this scenario.
Actually the repeater should work fine because I am going to store all the properties such as MaxLength and Size etc. in the datatable and then use my Container item to dynamically set the MaxLength etc. of the textboxes.  So the question I still have is the original and how do I loop through these controls and retreive the values of the textbox and also the first column which will be text or I guess I could use a label.  Its all going to be in my datatable other than the typed text of the user in the textboxes.
When you have to access the controls? On ItemDataBound or on ItemCreated?


-Nauman.
On the submit of a button so neither.  The repeater I dont think has those methods does it?  Either way I need to access the controls on the form.  The repeater just builds the table for me.