This message was discovered on ASPFriends.com 'aspngfreeforall' list.
| Uma Ayyanathan |
<script runat="server"> Public objDatabase as new Waide.DataUtility Public ds as new System.Data.DataSet Public count as Integer dim strSQL as String
Sub Page_Load() personid.Text = request("id") DataBind() SetData() End Sub
Sub DataBind() If ((personid.Text = "") or (personid.Text = "null")) then 'do nothing... Else
objDatabase.strsql = "spGetPersonRolesNew " & Request("id") objDatabase.Initialize() ds = objDatabase.GetDataSet(objDatabase.strsql) RoleDesignation.DataSource = ds RoleDesignation.DataBind() objDatabase = Nothing End if End Sub
Private Sub SetData() Dim tbl as New Table() Dim tblCell as New TableCell()
Dim maxcount as Integer = ds.Tables(0).DefaultView.count For count = 0 To maxcount-1
Dim lblRolenameval as Label = New Label() Dim lblRolecountval as Label = New Label() Dim phRolename as PlaceHolder = New PlaceHolder Dim phRolecount as PlaceHolder = New PlaceHolder
lblRolenameval.id = "lblRolenameval_" & count lblRolenameval.Text = ds.Tables(0).DefaultView.Item(count).Item("role_name").ToString phRolename.Controls.Add(lblRolenameval) lblRolecountval.id = "lblRolecountval_" & count lblRolecountval.Text = ds.Tables(0).DefaultView.Item(count).Item("role_count").ToString phRolecount.Controls.Add(lblRolecountval)
Dim chkRoleDesigval as CheckBox = New CheckBox() chkRoleDesigval.id = "chkRoleDesigval_" & count If ds.Tables(0).DefaultView.Item(count).Item("role_designated").ToString = "0" Then chkRoleDesigval.checked = False Else chkRoleDesigval.checked = True End If Dim phCheckBox as PlaceHolder = New PlaceHolder phCheckBox.Controls.Add(chkRoleDesigval)
Dim spacer As LiteralControl = New LiteralControl("<br>")
Panel1.Controls.Add(phRolename) Panel1.Controls.Add(phRolecount) Panel1.Controls.Add(phCheckBox) Panel1.Controls.Add(spacer) Next
End Sub
Sub btnSaveRoleDesig_onclick(obj as object, e as eventargs) response.write(chkRoleDesigval.value) End Sub
</script> <body id="BodyTag" runat=server/><form runat=server> <asp:Label id=personid runat=server visible=false /> <asp:Label id=testLabel runat=server /> <asp:DataGrid id=RoleDesignation runat=server visible = false> </asp:DataGrid> <ASP:TABLE GridLines=1> <ASP:TableRow> <ASP:TableCell id=tblRolename> <ASP:Label id="lblRolename" CssClass="formBold" text="Role Name" runat=server/> </ASP:TableCell> <ASP:TableCell> <ASP:Label id="lblRoleCount" Size="32" CssClass="formBold" text="Role Count" runat=server/> </ASP:TableCell> <ASP:TableCell> <ASP:Label id="lblRoleDesignated" Size="32" CssClass="formBold" text="Role Designated" runat=server/> </ASP:TableCell> </ASP:TableRow> </ASP:TABLE> <table width=100% > <ASP:Panel id=panel1 runat=server/> <tr><td> <ASP:Button id="btnSaveRoleDesig" CssClass="form" text="Save" onclick="btnSaveRoleDesig_onclick" runat=server/> </td></tr> </table> </form></body>
_______________________________________________________________________
The above code adds controls programmatically with values driven from the database. When the user hits the save button, I am having a hard time to pull out the checkbox values designed programmatically at runtime. How do I pull out the checkbox values in the btnSaveRoleDesig_onclick event? If I try to write response.write(chkRoleDesigval.checked) or chkRoleDesigval_0.checked in the onclick event, it gives the error message that 'chkRoleDesigval or chkRoleDesigval_0 is not declared'. Any ideas on how to grab the checkbox values which are designed in the Page Load event? Thanks, Uma
_________________________________________________________________ Join the world’s largest e-mail service with MSN Hotmail. http://www.hotmail.com
|
|
| |
| | |
|
|
|
|