D
Derek
I have an aspx page where I use a reversebind and
templates to edit the entire datagrid at one time. I
added a textbox and button to change the parameter
criteria and then rerun the databind2 procedure. That
works fine the data is requeried and the new results are
displayed in the datagrid and the reversebind works for
saving the information. However if I add another text
box or dropdown box it does not seem to requery
correctly. If I remove the reversebind it will, but
without the reversebind I can not save changes to the
datagrid as a whole. I think I understand why using the
ddcp.selectedindex change sub will not work because it is
posting back however I can not figure out why adding an
additional text box for input and placing that within the
button1 command is not. I have looked at the stored
procedure also. I need to be able to either look at all
or a particular type of cp. I would prefer to use a drop
down box either inside or out of the button1 command.
Any help would appreciated. Thanks in advance
Here is both the code for page and stored_proc. page
also draws really slow:
Private Sub Page_Load(ByVal sender As System.Object,
ByVal e As System.EventArgs) Handles MyBase.Load
If Not IsPostBack Then
datcurrent = Date.Now.ToShortDateString
lblselectedcaldt.Text = DateAdd
(DateInterval.Day, 1, datcurrent)
squad = Request.QueryString("usersquad")
lblusersquad.Text = squad
lblselectedCP.Text = ddcp.SelectedValue
BindData2()
lbltoday.Text = datcurrent
txtdaysout.Text = ""
Else
ReverseBind()
End If
End Sub
Sub BindData2()
Dim cp As String
'cp = "c"
'If ddcp.SelectedIndex > -1 Then
cp = lblselectedCP.Text
'ElseIf ddcp.SelectedIndex = -1 Then
' cp = "%"
'End If
'If lblselectedCP.Text = "" Then
'cp = "%"
'Else
' cp = lblselectedCP.Text
'End If
sdate = CType(lblselectedcaldt.Text, DateTime)
If lbl4days.Text = "" Then
daysout = 36
Else
daysout = CType(lbl4days.Text, Integer)
End If
'squad = lblusersquad.Text
SqlSelectCommand1.Parameters("@sdate").Value =
sdate
SqlSelectCommand1.Parameters("@time").Value =
daysout
SqlSelectCommand1.Parameters("@squad").Value =
lblusersquad.Text
If lblselectedCP.Text = "All" Then
SqlSelectCommand1.Parameters("@cp").Value
= "%"
Else
SqlSelectCommand1.Parameters("@cp").Value =
lblselectedCP.Text
End If
'SqlConnection1.Open()
SqlDataAdapter2.Fill(DsCrewNotify1)
DataGrid2.DataBind()
_LastEditedPage = DataGrid2.CurrentPageIndex
'SqlConnection1.Close()
End Sub
Public Sub ReverseBind()
Dim gridrow As DataGridItem
Dim datarow As dsCrewNotify.og_getCrewNotifyRow
For Each gridrow In DataGrid2.Items
datarow = DsCrewNotify1.og_getCrewNotify
(gridrow.DataSetIndex)
datarow.notified() = CType(gridrow.FindControl
("chkNotify"), CheckBox).Checked
DsCrewNotify1.og_getCrewNotify
(gridrow.DataSetIndex).ItemArray = datarow.ItemArray
Next
End Sub
Protected Overrides Sub LoadViewState(ByVal
savedstate As Object)
MyBase.LoadViewState(savedstate)
If (Not Me.ViewState("Data") Is Nothing) Then
DsCrewNotify1 = CType(Me.ViewState("Data"),
dsCrewNotify)
End If
If (Not Me.ViewState("LastEditedPage") Is
Nothing) Then
_LastEditedPage = CType(Me.ViewState
("LastEditedPage"), Integer)
End If
End Sub
Protected Overrides Function saveViewState() As Object
Me.ViewState("Data") = DsCrewNotify1
Me.ViewState("LastEditedPage") = _LastEditedPage
Return (MyBase.SaveViewState())
End Function
Private Sub DataGrid1_ItemDataBound(ByVal sender As
Object, ByVal e As
System.Web.UI.WebControls.DataGridItemEventArgs) Handles
DataGrid2.ItemDataBound
If (e.Item.ItemType = ListItemType.Item Or
e.Item.ItemType = ListItemType.AlternatingItem) Then
Dim datarow As
dsCrewNotify.og_getCrewNotifyRow
datarow = CType(CType(e.Item.DataItem,
DataRowView).Row, dsCrewNotify.og_getCrewNotifyRow)
CType(e.Item.FindControl("chkNotify"),
CheckBox).Checked = datarow.notified
End If
End Sub
Sub updateData()
Dim gridrow As DataGridItem
Dim datarow As dsCrewNotify.og_getCrewNotifyRow
Dim dscrewnotify As DataSet
Dim chkbox As CheckBox
Dim strnotify As String
Dim intid As Integer
For Each gridrow In DataGrid2.Items
datarow = DsCrewNotify1.og_getCrewNotify
(gridrow.DataSetIndex)
intid = datarow.Item(0)
datarow.notified() = CType(gridrow.FindControl
("chknotify"), CheckBox).Checked
DsCrewNotify1.og_getCrewNotify
(gridrow.DataSetIndex).ItemArray = datarow.ItemArray
strnotify = CType(gridrow.FindControl
("chkNotify"), CheckBox).Checked
SqlUpdateCommand1.Parameters("@notify").Value
= strnotify
SqlUpdateCommand1.Parameters
("@schedid").Value = intid
SqlConnection1.Open()
SqlUpdateCommand1.ExecuteNonQuery()
SqlConnection1.Close()
Next
'BindData2()
ReverseBind()
End Sub
Sub doUpdate(ByVal sender As Object, ByVal e As
DataGridCommandEventArgs)
If e.CommandName = "Update" Then
DataGrid2.AllowPaging = False
' DataGrid2.AllowSorting = True
DataGrid2.DataSource =
DsCrewNotify1.og_getCrewNotify
ReverseBind()
updateData()
End If
End Sub
Private Sub Button1_Click(ByVal sender As
System.Object, ByVal e As System.EventArgs) Handles
Button1.Click
Dim numhours As Integer
If txtdaysout.Text = "" Then
numhours = 36
Else
numhours = (CType(txtdaysout.Text, Integer) *
24) + 12
End If
' numhours = (CType(txtdaysout.Text, Integer) *
24) + 12
lbl4days.Text = numhours
BindData2()
End Sub
Sub ddcp_SelectedIndexChanged(ByVal sender As Object,
ByVal e As System.EventArgs) Handles
ddcp.SelectedIndexChanged
If ddcp.SelectedIndex > -1 Then
lblselectedCP.Text = ddcp.SelectedValue
BindData2()
End If
End Sub
End Class
Stored Proc::
CREATE PROCEDURE *********
@sdate as datetime
, @time as int
, @squad as nvarchar(10)
, @cp as nvarchar(10)
AS
Select
s.scheduleid
, s.namelast
, s.namefirst
, s.startdate
, s.stopdate
, s.notified
, e.mission_id
, e.eventName
, e.eventtype
, dateadd(hh,-5,e.alerttime) as alertime
, dateadd(hh, -5,e.showtime) as showtime
, et.EventCat
, e.eventsquadron
, e.eventsid
, e.eventtitle
, p.phonehome
, p.phonecell
, cp.crw_pstn_dty_cd
--, a.FLYR_ORG_UNIT_ID
--, a.person_id
From ****** as p
join ***** s
on p.ssn = s.ssn
join ***** e
on s.eventsid = e.eventsid
join ****** et
on e.eventtype = et.eventtypelong
left join ******* a
on a.person_id = p.ssn
left join ******* cp
on a.person_id = cp.person_id
Where
--((dateadd(hh, -5,e.startdate)) between @sdate and
(dateadd(hh,36,@sdate)))
(dateadd(hh,-5,e.alerttime) between @sdate and (dateadd
(hh,@time,@sdate)))
and substring(a.FLYR_ORG_UNIT_ID,1,4) like @squad
and cp.arcft_asg_evt_id = '01'
and cp.crw_pstn_dty_cd like @cp
order by e.alerttime,e.eventtitle,s.namelast
GO
templates to edit the entire datagrid at one time. I
added a textbox and button to change the parameter
criteria and then rerun the databind2 procedure. That
works fine the data is requeried and the new results are
displayed in the datagrid and the reversebind works for
saving the information. However if I add another text
box or dropdown box it does not seem to requery
correctly. If I remove the reversebind it will, but
without the reversebind I can not save changes to the
datagrid as a whole. I think I understand why using the
ddcp.selectedindex change sub will not work because it is
posting back however I can not figure out why adding an
additional text box for input and placing that within the
button1 command is not. I have looked at the stored
procedure also. I need to be able to either look at all
or a particular type of cp. I would prefer to use a drop
down box either inside or out of the button1 command.
Any help would appreciated. Thanks in advance
Here is both the code for page and stored_proc. page
also draws really slow:
Private Sub Page_Load(ByVal sender As System.Object,
ByVal e As System.EventArgs) Handles MyBase.Load
If Not IsPostBack Then
datcurrent = Date.Now.ToShortDateString
lblselectedcaldt.Text = DateAdd
(DateInterval.Day, 1, datcurrent)
squad = Request.QueryString("usersquad")
lblusersquad.Text = squad
lblselectedCP.Text = ddcp.SelectedValue
BindData2()
lbltoday.Text = datcurrent
txtdaysout.Text = ""
Else
ReverseBind()
End If
End Sub
Sub BindData2()
Dim cp As String
'cp = "c"
'If ddcp.SelectedIndex > -1 Then
cp = lblselectedCP.Text
'ElseIf ddcp.SelectedIndex = -1 Then
' cp = "%"
'End If
'If lblselectedCP.Text = "" Then
'cp = "%"
'Else
' cp = lblselectedCP.Text
'End If
sdate = CType(lblselectedcaldt.Text, DateTime)
If lbl4days.Text = "" Then
daysout = 36
Else
daysout = CType(lbl4days.Text, Integer)
End If
'squad = lblusersquad.Text
SqlSelectCommand1.Parameters("@sdate").Value =
sdate
SqlSelectCommand1.Parameters("@time").Value =
daysout
SqlSelectCommand1.Parameters("@squad").Value =
lblusersquad.Text
If lblselectedCP.Text = "All" Then
SqlSelectCommand1.Parameters("@cp").Value
= "%"
Else
SqlSelectCommand1.Parameters("@cp").Value =
lblselectedCP.Text
End If
'SqlConnection1.Open()
SqlDataAdapter2.Fill(DsCrewNotify1)
DataGrid2.DataBind()
_LastEditedPage = DataGrid2.CurrentPageIndex
'SqlConnection1.Close()
End Sub
Public Sub ReverseBind()
Dim gridrow As DataGridItem
Dim datarow As dsCrewNotify.og_getCrewNotifyRow
For Each gridrow In DataGrid2.Items
datarow = DsCrewNotify1.og_getCrewNotify
(gridrow.DataSetIndex)
datarow.notified() = CType(gridrow.FindControl
("chkNotify"), CheckBox).Checked
DsCrewNotify1.og_getCrewNotify
(gridrow.DataSetIndex).ItemArray = datarow.ItemArray
Next
End Sub
Protected Overrides Sub LoadViewState(ByVal
savedstate As Object)
MyBase.LoadViewState(savedstate)
If (Not Me.ViewState("Data") Is Nothing) Then
DsCrewNotify1 = CType(Me.ViewState("Data"),
dsCrewNotify)
End If
If (Not Me.ViewState("LastEditedPage") Is
Nothing) Then
_LastEditedPage = CType(Me.ViewState
("LastEditedPage"), Integer)
End If
End Sub
Protected Overrides Function saveViewState() As Object
Me.ViewState("Data") = DsCrewNotify1
Me.ViewState("LastEditedPage") = _LastEditedPage
Return (MyBase.SaveViewState())
End Function
Private Sub DataGrid1_ItemDataBound(ByVal sender As
Object, ByVal e As
System.Web.UI.WebControls.DataGridItemEventArgs) Handles
DataGrid2.ItemDataBound
If (e.Item.ItemType = ListItemType.Item Or
e.Item.ItemType = ListItemType.AlternatingItem) Then
Dim datarow As
dsCrewNotify.og_getCrewNotifyRow
datarow = CType(CType(e.Item.DataItem,
DataRowView).Row, dsCrewNotify.og_getCrewNotifyRow)
CType(e.Item.FindControl("chkNotify"),
CheckBox).Checked = datarow.notified
End If
End Sub
Sub updateData()
Dim gridrow As DataGridItem
Dim datarow As dsCrewNotify.og_getCrewNotifyRow
Dim dscrewnotify As DataSet
Dim chkbox As CheckBox
Dim strnotify As String
Dim intid As Integer
For Each gridrow In DataGrid2.Items
datarow = DsCrewNotify1.og_getCrewNotify
(gridrow.DataSetIndex)
intid = datarow.Item(0)
datarow.notified() = CType(gridrow.FindControl
("chknotify"), CheckBox).Checked
DsCrewNotify1.og_getCrewNotify
(gridrow.DataSetIndex).ItemArray = datarow.ItemArray
strnotify = CType(gridrow.FindControl
("chkNotify"), CheckBox).Checked
SqlUpdateCommand1.Parameters("@notify").Value
= strnotify
SqlUpdateCommand1.Parameters
("@schedid").Value = intid
SqlConnection1.Open()
SqlUpdateCommand1.ExecuteNonQuery()
SqlConnection1.Close()
Next
'BindData2()
ReverseBind()
End Sub
Sub doUpdate(ByVal sender As Object, ByVal e As
DataGridCommandEventArgs)
If e.CommandName = "Update" Then
DataGrid2.AllowPaging = False
' DataGrid2.AllowSorting = True
DataGrid2.DataSource =
DsCrewNotify1.og_getCrewNotify
ReverseBind()
updateData()
End If
End Sub
Private Sub Button1_Click(ByVal sender As
System.Object, ByVal e As System.EventArgs) Handles
Button1.Click
Dim numhours As Integer
If txtdaysout.Text = "" Then
numhours = 36
Else
numhours = (CType(txtdaysout.Text, Integer) *
24) + 12
End If
' numhours = (CType(txtdaysout.Text, Integer) *
24) + 12
lbl4days.Text = numhours
BindData2()
End Sub
Sub ddcp_SelectedIndexChanged(ByVal sender As Object,
ByVal e As System.EventArgs) Handles
ddcp.SelectedIndexChanged
If ddcp.SelectedIndex > -1 Then
lblselectedCP.Text = ddcp.SelectedValue
BindData2()
End If
End Sub
End Class
Stored Proc::
CREATE PROCEDURE *********
@sdate as datetime
, @time as int
, @squad as nvarchar(10)
, @cp as nvarchar(10)
AS
Select
s.scheduleid
, s.namelast
, s.namefirst
, s.startdate
, s.stopdate
, s.notified
, e.mission_id
, e.eventName
, e.eventtype
, dateadd(hh,-5,e.alerttime) as alertime
, dateadd(hh, -5,e.showtime) as showtime
, et.EventCat
, e.eventsquadron
, e.eventsid
, e.eventtitle
, p.phonehome
, p.phonecell
, cp.crw_pstn_dty_cd
--, a.FLYR_ORG_UNIT_ID
--, a.person_id
From ****** as p
join ***** s
on p.ssn = s.ssn
join ***** e
on s.eventsid = e.eventsid
join ****** et
on e.eventtype = et.eventtypelong
left join ******* a
on a.person_id = p.ssn
left join ******* cp
on a.person_id = cp.person_id
Where
--((dateadd(hh, -5,e.startdate)) between @sdate and
(dateadd(hh,36,@sdate)))
(dateadd(hh,-5,e.alerttime) between @sdate and (dateadd
(hh,@time,@sdate)))
and substring(a.FLYR_ORG_UNIT_ID,1,4) like @squad
and cp.arcft_asg_evt_id = '01'
and cp.crw_pstn_dty_cd like @cp
order by e.alerttime,e.eventtitle,s.namelast
GO