|
code
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Creating N rows of controlsHi;
When creating a new report, I need to have a table with 0 – N rows, one for each variable in a report. I don’t know how many of these there are until the user uploads the report template file so I can't prebuild N rows in the aspx file. Once I do know, each row has a checkbox, a label, and a dropdownlist (each a cell in the table). And when there is a post-back, each of these need to be set to the values they previously had. How do I set this up and how do I access the values? Hi Dave,
You need to create your controls programmatically, including all of the controls they contain. Then add the controls to a placeholder. Here's a quick example that should give you the idea. Let us know if this helps? Ken Microsoft MVP [ASP.NET] <%@ Page Language="VB" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <script runat="server"> Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Dim gv As GridView Dim intCounter As Integer If Not IsPostBack Then For intCounter = 0 To 5 gv = New GridView gv.ID = "gv" & intCounter.ToString gv.DataSource = CreateDataSource() gv.DataBind() PlaceHolder1.Controls.Add(gv) Next End If End Sub Function CreateDataSource() As Data.DataTable Dim dt As New Data.DataTable Dim dr As Data.DataRow dt.Columns.Add(New Data.DataColumn _ ("StringValue", GetType(String))) dt.Columns.Add(New Data.DataColumn _ ("StringValue2", GetType(String))) Dim i As Integer For i = 0 To 5 dr = dt.NewRow() dr(0) = i.ToString & "@none.com" dr(1) = "Item " & i.ToString() dt.Rows.Add(dr) Next i Return dt End Function </script> <html xmlns="http://www.w3.org/1999/xhtml" > <head runat="server"> <title>Untitled Page</title> </head> <body> <form id="form1" runat="server"> <div> <asp:placeholder id="PlaceHolder1" runat="server"></asp:placeholder> </div> </form> </body> </html> Show quoteHide quote "David Thielen" <thielen@nospam.nospam> wrote in message news:AAB6BBD0-F854-4976-B080-8F8928E435BE@microsoft.com... > Hi; > > When creating a new report, I need to have a table with 0 - N rows, one > for > each variable in a report. I don't know how many of these there are until > the > user uploads the report template file so I can't prebuild N rows in the > aspx > file. > > Once I do know, each row has a checkbox, a label, and a dropdownlist (each > a > cell in the table). And when there is a post-back, each of these need to > be > set to the values they previously had. How do I set this up and how do I > access the values? > > -- > thanks - dave > david_at_windward_dot_net > http://www.windwardreports.com > Hi;
Ok, will try this. I was hoping that ASP had a construct like JSPs do where you can put a for loop in the jsp (aspx) file so everything is right there and no need to touch a code behind to add controls. Show quoteHide quote "Ken Cox - Microsoft MVP" wrote: > Hi Dave, > > You need to create your controls programmatically, including all of the > controls they contain. Then add the controls to a placeholder. > > Here's a quick example that should give you the idea. > > Let us know if this helps? > > Ken > Microsoft MVP [ASP.NET] > > <%@ Page Language="VB" %> > > <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" > "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> > > <script runat="server"> > > Protected Sub Page_Load(ByVal sender As Object, ByVal e As > System.EventArgs) > Dim gv As GridView > Dim intCounter As Integer > If Not IsPostBack Then > For intCounter = 0 To 5 > gv = New GridView > gv.ID = "gv" & intCounter.ToString > gv.DataSource = CreateDataSource() > gv.DataBind() > PlaceHolder1.Controls.Add(gv) > Next > End If > End Sub > > Function CreateDataSource() As Data.DataTable > Dim dt As New Data.DataTable > Dim dr As Data.DataRow > dt.Columns.Add(New Data.DataColumn _ > ("StringValue", GetType(String))) > dt.Columns.Add(New Data.DataColumn _ > ("StringValue2", GetType(String))) > Dim i As Integer > For i = 0 To 5 > dr = dt.NewRow() > dr(0) = i.ToString & "@none.com" > dr(1) = "Item " & i.ToString() > dt.Rows.Add(dr) > Next i > Return dt > > End Function > </script> > > <html xmlns="http://www.w3.org/1999/xhtml" > > <head runat="server"> > <title>Untitled Page</title> > </head> > <body> > <form id="form1" runat="server"> > <div> > <asp:placeholder id="PlaceHolder1" runat="server"></asp:placeholder> > > </div> > </form> > </body> > </html> > > > "David Thielen" <thielen@nospam.nospam> wrote in message > news:AAB6BBD0-F854-4976-B080-8F8928E435BE@microsoft.com... > > Hi; > > > > When creating a new report, I need to have a table with 0 - N rows, one > > for > > each variable in a report. I don't know how many of these there are until > > the > > user uploads the report template file so I can't prebuild N rows in the > > aspx > > file. > > > > Once I do know, each row has a checkbox, a label, and a dropdownlist (each > > a > > cell in the table). And when there is a post-back, each of these need to > > be > > set to the values they previously had. How do I set this up and how do I > > access the values? > > > > -- > > thanks - dave > > david_at_windward_dot_net > > http://www.windwardreports.com > > > > > Hi Dave,
I think you can also consider using the ASP.NET¡¯s template databound control. For example, we can use the Repeater control and put those certain controls we want to repeatedly create in the ItemTemplate of the repeater. At runtime, we can dynamically bind a simple collection(List, Array or IEnumarble....) to the repeater and perform databinding, this can help us make a list of those controls in the Itemtemplate and the repeat count just match the datasource's length. Hope this also helps. Regards, Steven Cheng Microsoft Online Support Get Secure! www.microsoft.com/security (This posting is provided "AS IS", with no warranties, and confers no rights.) This works very nicely - thank you
Show quoteHide quote "Steven Cheng[MSFT]" wrote: > > Hi Dave, > > I think you can also consider using the ASP.NET¡¯s template databound > control. For example, we can use the Repeater control and put those certain > controls we want to repeatedly create in the ItemTemplate of the repeater. > At runtime, we can dynamically bind a simple collection(List, Array or > IEnumarble....) to the repeater and perform databinding, this can help us > make a list of those controls in the Itemtemplate and the repeat count just > match the datasource's length. > > Hope this also helps. > > > Regards, > > Steven Cheng > Microsoft Online Support > > Get Secure! www.microsoft.com/security > (This posting is provided "AS IS", with no warranties, and confers no > rights.) > > > > You're welcome.
regards, Steven Cheng Microsoft Online Support Get Secure! www.microsoft.com/security (This posting is provided "AS IS", with no warranties, and confers no rights.)
How to access control in FormView
paging control? ObjectDataSource ... could not find a non-generic method ... that has parameters: ... How to add a dropdownlist to the column header in a GridView? Custom Web control question FormView/ItemTemplate - MultiView, Radio, & checkbox Overriding Calendar.CreateChildControls Exporting Datagrid to Excel PostBack and dynamically created controls Hotspots with Images?? |
|||||||||||||||||||||||