Need some advice

xinyue

New Member
I've posted this question once already so I apologize for the repetitivness but...<BR>I need to dynamically add a table to my web form. The table has 2 columns and n number of rows - in the second column of each row I need to add a checkbox. This much I have accomplished. <BR>My problems arise when I try to determine which checkboxes were checked. I now understand that dynamically added web controls cannot maintain state, so after I create the table I save it in a session variable. After each post back I use the session variable to re-add the table to the web form. Problem is that table does not accurately reflect what the user might have done between post backs (i.e. which checkboxes that might have checked/unchecked). Also, there are several ways that my form can be submitted. So, I guess I have several questions:<BR><BR>1) Does anyone have any experience with adding web controls dynamically and successfully maintaining state, who could give me some advice?<BR><BR>2) Could I do this with a user control, and would that somehow make this easier?<BR><BR>3) Can I funnel all of my different submit methods through a single event handler, like a page_onSubmit subroutine?<BR><BR>Thanks in advance<BR><BR>MasmithHmmm, well first off, is there any particular reason why you're not using the datagrid web control vs. building an html table? From the sound of things, it seems like a datagrid would be the way to go. <BR><BR>Once you have a datagrid built with a check box in a template column add an invisible label control with the id, eg.:<BR><BR> <asp:TemplateColumn HeaderText="Select A Set"><BR> <itemStyle Width="65"/> <BR> <ItemTemplate><BR> <asp:RadioButton id="selTempID" GroupName="RadioGroup1" runat="server"/><asp:TextBox Visible="false" id="templateSetID" Text='<%# DataBinder.Eval(Container.DataItem, "templateSetID")%>' runat="server" /><BR> </ItemTemplate> <BR> </asp:TemplateColumn><BR><BR>Then read this article, the first part is probably all you need:<BR><BR>http://dotnetjunkies.com/howto/default.aspx?id=25<BR><BR>As for handling all your submits, yeah, you can create a single submit routine and have them all call it on some event (onClick etc.) <BR><BR>])ry<BR><BR>I was under the impression that a datagrid was used to display data coming from an data store. Does that not necessarily have to be the case? I'll give it a shot. Thanks.It seemed like you had some form of a datasource with the sentence "The table has 2 columns and n number of rows" Is your table being created with an array? If so, with a little tweaking, that same array can be used as the datagrid datasource. Say you have a datagrid called genInfoGrid, then you'd do something like this:<BR><BR>dim genArray() AS string = yourArray<BR>genInfoGrid.DataSource = genArray<BR>genInfoGrid.DataBind<BR><BR>])ryI have an ActiveX object called 'map'. The map is made up of a number of layers. Each layer name needs to be in the table/grid. The layer name is accessed like this:<BR><BR>map.layers.item(i).name<BR><BR>I suppose I could loop through the layers and add each layer name to an array.<BR>Give that this is where I am coming from do you still think that the datagrid is the way to go?<BR><BR>I greatly appreciate your help, thanks<BR><BR>masmithhmm, how are you creating the table now? Are you looping through (or something similar) the available layer names to write out your rows anyway? If so, then populating an array to build a datagrid wouldn't be anymore taxing. On the flip side, it seems like map.layers.items is already a collection that may be easily bound to a datagrid.<BR><BR>Anyway, if you're going to create a variable grid-like structure of any sort in .NET my first instinct is to go with a datagrid. They're super quick and they make it pretty easy to add paging or sorting once you get the syntax worked out. Might want to consider turning off viewstate for the grid if you're not going to need it. All in all, yeah, I'd still use a datagrid, but it's certainly not the only way. <BR><BR>Hth, <BR><BR>])ryYeah, I was already looping through the layer names so it wouldn't be a big deal to populate an array, in fact I've already tried it out and built the datagrid. I'm going to go with it for now and see how it turns out. Thanks for the advice.<BR><BR>masmith
 
Back
Top