aspdotnet_website_programming thread: Databinding problem or invoking SelectedIndexChanged
I'm not sure if this is a databinding problem or what, but I'm having
problem with updating values when databinding. When my dropdown list is
changed, it will regenerate the table just fine and rebind all the new
values. But, I have another postback where it doesn't generate the
SelectedIndexChanged event so I try calling my CreateSecurityTable
method from pageload and tell it to bind the new values but it just
keeps the old values when the page is loaded. I know it is updating the
dataset that I am binding to. One idea I had was to just call the
SelectedIndexChange method but that didn't work. I was wondering if
there was a way to have the server actually generate a
SelectedIndexChanged event from within my Page_Load method or from my
client side function that is generating the postback?
I included a copy of the selectedindexchanged method and the method that
is doing my databinding.
Thaank in Advance,
Chris Page
Developer
NAT, Inc.
(xxx) xxx-xxxx x3040
Private Sub drpUserID_SelectedIndexChanged(ByVal sender As
System.Object, ByVal e As System.EventArgs) Handles
drpUserID.SelectedIndexChanged
' if they selected the new user, the call do NewUser() stuff
If CInt(drpUserID.SelectedItem.Value) = -1 And hdnIsNew.Value <>
"1" Then
NewUser()
ElseIf hdnIsNew.Value = "1" Or hdnIsCopy.Value = "1" Then
' disable validation controls so they don't appear on this
postback
btnSave.Enabled = True
btnCopy.Enabled = True
hdnUpdateRule.Value = "1"
hdnIsDirty.Value = "1"
' create the rules table based on a template ID if there is
one
' otherwise just blank
If hdnIsCopy.Value = "1" Then
If hdnTemplateID.Value <> "-1" Then
CreateSecurityTable(hdnTemplateID.Value, True)
pnlCategories.DataBind()
End If
Else
CreateSecurityTable(hdnTemplateID.Value, True)
pnlCategories.DataBind()
End If
txtTemplate.Text = hdnTemplateName.Value
' temporarily make the New User item in the listbox the name
from
' the NewUser.aspx. If cancelled, then set the listbox to
the 1st blank value
If hdnIsNew.Value = "1" Then
' if they associated this user w/ a template, then it
can't be a template user
If (hdnTemplateName.Value <> "") Or Not
Session(Session.SessionID & "blnCanCreateTemplate") Then
chkTemplateUser.Enabled = False
ElseIf Session(Session.SessionID &
"blnCanCreateTemplate") Then
' if they can create templates, enable the checkbox
chkTemplateUser.Enabled = True
End If
' if they only have permission to create templates (not
add users) then check the template
' box and disable it so they can't uncheck it
If Session(Session.SessionID & "blnCanCreateTemplate")
And Not Session(Session.SessionID & "blnCanAdd") Then
chkTemplateUser.Checked = True
chkTemplateUser.Enabled = False
Else
chkTemplateUser.Checked = False
End If
End If
Else
' if not a new user, just load the user info and recreate
the rules table
LoadUserInfo()
CreateSecurityTable(CInt(drpUserID.SelectedItem.Value),
True)
btnSave.Enabled = False
pnlCategories.DataBind()
If drpUserID.Items(0).Value <> "-2" Then
' only add the "New User" option if they have permission
to create users and/or templates
If Session(Session.SessionID & "blnCanAdd") Or
Session(Session.SessionID & "blnCanCreateTemplate") Then
drpUserID.Items.Insert(0, New
System.Web.UI.WebControls.ListItem("... New User", -1))
End If
drpUserID.Items.Insert(0, New
System.Web.UI.WebControls.ListItem("", -2))
End If
End If
' keeps track of current index so that javascript can switch
back to this index if they
' try changing the user when the page is dirty
hdnCurrentUserIndex.Value = drpUserID.SelectedIndex
End Sub
Private Sub CreateSecurityTable(ByVal intUserID As Integer, ByVal
blnUserChanged As Boolean)
Dim rptCategory As New System.Web.UI.WebControls.Repeater()
Dim xmlReader As System.Xml.XmlReader
Dim oXMLDoc As New System.Xml.XmlDocument()
Dim i As Integer
Dim tblCategory As System.Web.UI.WebControls.Table
Dim tbrCategory As System.Web.UI.WebControls.TableRow
Dim tbcCategory As System.Web.UI.WebControls.TableCell
Dim imgPlusMinus As System.Web.UI.WebControls.Image
Dim lblCategoryName As System.Web.UI.WebControls.Label
Dim objUserSecurity As New ServiceOrderWeb.cUserSecurity()
Dim strRuleID As String
Dim stcRule As ServiceOrderWeb.cUserSecurity.SecurityRule
Dim dtbTemplate As New Data.DataTable()
Dim dsUserSecurity As New Data.DataSet()
dtbTemplate.Columns.Add("irule_id")
dtbTemplate.Columns.Add("srule_description")
dtbTemplate.Columns.Add("bthas_amount")
dtbTemplate.Columns.Add("stextbox_class")
dtbTemplate.Columns.Add("btaccess")
dtbTemplate.Columns.Add("camount")
Dim strOutput As String
Dim drRule As Data.DataRow
Dim dtbRules As Data.DataTable
Dim strCurrentCategory As String
Dim arrRowValues(5) As String
pnlCategories.Controls.Clear()
If blnUserChanged Then
' Code is here to fill a dataset
xmlUserSecurity.InnerHtml = dsUserSecurity.GetXml()
End If
If dsUserSecurity.Tables.Count = 0 Then
oXMLDoc.LoadXml(xmlUserSecurity.InnerHtml)
xmlReader = New System.Xml.XmlNodeReader(oXMLDoc)
dsUserSecurity.ReadXml(xmlReader)
End If
pnlCategories.Controls.Clear()
For i = 0 To dsUserSecurity.Tables.Count - 1
tblCategory = New System.Web.UI.WebControls.Table()
tblCategory.BorderStyle = BorderStyle.Solid
tblCategory.BorderWidth
System.Web.UI.WebControls.Unit.Pixel(1)
tblCategory.CellPadding = 0
tblCategory.CellSpacing = 0
tblCategory.Width
System.Web.UI.WebControls.Unit.Pixel(400)
tbrCategory = New System.Web.UI.WebControls.TableRow()
tbrCategory.CssClass = "rowHeader"
tbcCategory = New System.Web.UI.WebControls.TableCell()
imgPlusMinus = New System.Web.UI.WebControls.Image()
imgPlusMinus.ID = "img" & dsUserSecurity.Tables(i).TableName
imgPlusMinus.ImageUrl = "images/expanded.gif"
imgPlusMinus.Attributes.Add("onclick", "ChangeDiv('tbr" &
dsUserSecurity.Tables(i).TableName & "', this.id)")
tbcCategory.Controls.Add(imgPlusMinus)
lblCategoryName = New System.Web.UI.WebControls.Label()
lblCategoryName.Text = " " &
dsUserSecurity.Tables(i).TableName
tbcCategory.Controls.Add(lblCategoryName)
tbrCategory.Cells.Add(tbcCategory)
tblCategory.Rows.Add(tbrCategory)
tbrCategory = New System.Web.UI.WebControls.TableRow()
tbrCategory.ID = "tbr" & dsUserSecurity.Tables(i).TableName
tbcCategory = New System.Web.UI.WebControls.TableCell()
rptCategory = New System.Web.UI.WebControls.Repeater()
rptCategory.ID = "rpt" & dsUserSecurity.Tables(i).TableName
rptCategory.HeaderTemplate = rptRules.HeaderTemplate
rptCategory.ItemTemplate = rptRules.ItemTemplate
rptCategory.AlternatingItemTemplate
rptRules.AlternatingItemTemplate
rptCategory.FooterTemplate = rptRules.FooterTemplate
If blnUserChanged Then
rptCategory.DataSource = dsUserSecurity
rptCategory.DataMember
dsUserSecurity.Tables(i).TableName
'rptCategory.DataBind()
End If
tbcCategory.Controls.Add(rptCategory)
tbrCategory.Cells.Add(tbcCategory)
tblCategory.Rows.Add(tbrCategory)
pnlCategories.Controls.Add(tblCategory)
Next i
End Sub