473,503 Members | 1,697 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Programmatical Parameters w/MultiRowEdit on DataGrid

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

Nov 22 '05 #1
3 1743
Hi Derek,

I am not confident that I have understood the problem clearly. Did you need
to add a TextBox or Dropdownlist to let user select some values, and then
requery the database. If so, after user input the value and click a button
to post back, you need to execute BindData2() in PostBack, Is this right?

Luke
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)

Nov 22 '05 #2

Yes, I want to call binddata2() on button1_click. It
seems the reverse bind is causing the issue however If I
remove that I can not use the save btn update the
database with multiple selections.

The page is set up so that on load if notispostback it
executes Binddata2() else it executes reversebind(). On
the page load the stored procedure is sent all default
parameters (%) to pull all the data. When the daysout
textbox receives input and the go button is clicked
Binddata2() is called and requeries fine. It is when I
add another textbox asking for input for another filter
parameter that it does not execute the stored procedure
correctly. Example they choose to filter based on "p".
It does not change the parameter to pull records only
with "p". The confusing part is that it will execute
binddata2() with the one textbox.

I would prefer to use the dropdown box with or without
the GO btn but if I could get the text box to work that
would be great. The stored procedure works fine in query
analyzer.

Hope this gives you a little more information.
I am including the Html which may help you to see what I
am trying to do. Thanks for your help, it is appreciated
very much

<%@ Page Language="vb" AutoEventWireup="false"
Codebehind="getEventTitles.aspx.vb"
Inherits="CrewNotify.getEventTitles"%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0
Transitional//EN">

<HTML>

<HEAD>

<title>getEventTitles</title>

<meta content="Microsoft Visual
Studio .NET 7.1" name="GENERATOR">

<meta content="Visual Basic .NET
7.1" name="CODE_LANGUAGE">

<meta content="JavaScript"
name="vs_defaultClientScript">

<meta
content="http://schemas.microsoft.com/intellisense/ie5"
name="vs_targetSchema">

</HEAD>

<body MS_POSITIONING="GridLayout">

<form id="Form1" method="post"
runat="server">

<asp:datagrid
id=DataGrid2 style="Z-INDEX: 101; LEFT: 24px; POSITION:
absolute; TOP: 80px" runat="server"
OnItemCommand="doUpdate" ShowFooter="True"
AutoGenerateColumns="False" DataMember="og_getCrewNotify"
DataKeyField="scheduleid" DataSource="<%# DsCrewNotify1 %
" BorderColor="#000099" BorderStyle="None"

BorderWidth="1px" BackColor="White" CellPadding="3"
GridLines="Horizontal">
<SelectedItemStyle Font-Bold="True" ForeColor="White"
BackColor="#008A8C"></SelectedItemStyle>
<AlternatingItemStyle
BackColor="Gainsboro"></AlternatingItemStyle>
<ItemStyle Font-Size="X-Small" ForeColor="Black"
BackColor="#EEEEEE"></ItemStyle>
<HeaderStyle Font-Bold="True" ForeColor="White"
BackColor="#000084"></HeaderStyle>
<FooterStyle ForeColor="Black"
BackColor="#CCCCCC"></FooterStyle>

<Columns>
<asp:TemplateColumn HeaderText="CP">
<ItemTemplate>
<asp:Label id=lblCP
runat="server" Text='<%# DataBinder.Eval
(Container, "DataItem.crw_pstn_dty_cd") %>'>
</asp:Label>
</ItemTemplate>
</asp:TemplateColumn>
<asp:TemplateColumn SortExpression="namelast"
HeaderText="Crewmember">
<ItemTemplate>
<asp:Label id=Label8
runat="server" Text='<%# Container.DataItem("namelast")
&amp;", "&amp;Container.DataItem("namefirst") %>'>
</asp:Label>
</ItemTemplate>
</asp:TemplateColumn>
<asp:TemplateColumn SortExpression="eventtitle"
HeaderText="Alias">
<ItemTemplate>
<asp:Label id=lblAlias
runat="server" Text='<%# DataBinder.Eval
(Container, "DataItem.eventtitle") %>'>
</asp:Label>
</ItemTemplate>
</asp:TemplateColumn>
<asp:TemplateColumn Visible="False"
HeaderText="Category">
<ItemTemplate>
<asp:Label id=lblCategory
runat="server" Text='<%# DataBinder.Eval
(Container, "DataItem.EventCat") %>'>
</asp:Label>
</ItemTemplate>
</asp:TemplateColumn>
<asp:BoundColumn Visible="False" DataField="scheduleid"
SortExpression="scheduleid"
HeaderText="scheduleid"></asp:BoundColumn>
<asp:TemplateColumn HeaderText="Notified">
<ItemTemplate>
<asp:CheckBox id="chknotify"
runat="server"></asp:CheckBox>
</ItemTemplate>
<FooterTemplate>
<asp:Button id="Update"
runat="server" BackColor="Transparent"
CommandName="Update" Text="Save"></asp:Button>
</FooterTemplate>
</asp:TemplateColumn>
<asp:TemplateColumn HeaderText="Alert">
<ItemTemplate>
<asp:Label id=lblalert
runat="server" Text='<%# DataBinder.Eval
(Container, "DataItem.alertime", "{0:g}") %>'>
</asp:Label>
</ItemTemplate>
</asp:TemplateColumn>
<asp:TemplateColumn HeaderText="Show">
<ItemTemplate>
<asp:Label id=lblShow
runat="server" Text='<%# DataBinder.Eval
(Container, "DataItem.showtime", "{0:g}") %>'>
</asp:Label>
</ItemTemplate>
</asp:TemplateColumn>
<asp:TemplateColumn HeaderText="Home#">
<ItemTemplate>
<asp:Label id=lblhome
runat="server" Text='<%# DataBinder.Eval
(Container, "DataItem.phonehome") %>'>
</asp:Label>
</ItemTemplate>
</asp:TemplateColumn>
<asp:TemplateColumn HeaderText="Cell#">
<ItemTemplate>
<asp:Label id=lblcell
runat="server" Text='<%# DataBinder.Eval
(Container, "DataItem.phonecell") %>'>
</asp:Label>
</ItemTemplate>
</asp:TemplateColumn>
<asp:TemplateColumn HeaderText="Comments">
<HeaderStyle Width="100px"></HeaderStyle>
</asp:TemplateColumn>

</Columns>
<PagerStyle HorizontalAlign="Center" ForeColor="Black"
BackColor="#999999" Mode="NumericPages"></PagerStyle>
</asp:datagrid><asp:label id="lblselectedcaldt" style="Z-
INDEX: 102; LEFT: 136px; POSITION: absolute; TOP: 40px"
runat="server"></asp:label><asp:label id="Label1"
style="Z-INDEX: 103; LEFT: 136px; POSITION: absolute;
TOP: 16px" runat="server">Mission
date:</asp:label><asp:button id="Button1" style="Z-INDEX:
104; LEFT: 376px; POSITION: absolute; TOP: 40px"
runat="server"
BackColor="Gray" Width="40px"
Text="Go"></asp:button><asp:label id="lbl4days" style="Z-
INDEX: 105; LEFT: 544px; POSITION: absolute; TOP: 40px"
runat="server"></asp:label>

<asp:Label
id="Label2" style="Z-INDEX: 106; LEFT: 24px; POSITION:
absolute; TOP: 16px" runat="server">Today:</asp:Label>

<asp:Label
id="lbltoday" style="Z-INDEX: 107; LEFT: 24px; POSITION:
absolute; TOP: 40px" runat="server"></asp:Label>

<asp:TextBox
id="txtdaysout" style="Z-INDEX: 108; LEFT: 288px;
POSITION: absolute; TOP: 40px"
runat="server" Width="40px"></asp:TextBox>

<asp:Label
id="Label3" style="Z-INDEX: 109; LEFT: 280px; POSITION:
absolute; TOP: 16px" runat="server"># days to
view</asp:Label>

<asp:Label
id="Label9" style="Z-INDEX: 110; LEFT: 544px; POSITION:
absolute; TOP: 16px" runat="server">Hours
ahead:</asp:Label>

<asp:Label
id="lblusersquad" style="Z-INDEX: 111; LEFT: 768px;
POSITION: absolute; TOP: 24px"
runat="server" Visible="False"></asp:Label>

<asp:DropDownList
id="ddcp" style="Z-INDEX: 112; LEFT: 440px; POSITION:
absolute; TOP: 40px" runat="server"
Visible="False">
<asp:ListItem Value="C">C</asp:ListItem>
<asp:ListItem Value="L">L</asp:ListItem>
<asp:ListItem Value="P">P</asp:ListItem>
<asp:ListItem Value="S">S</asp:ListItem>
<asp:ListItem Value="All"
Selected="True">All</asp:ListItem>

</asp:DropDownList>

<asp:Label
id="Label10" style="Z-INDEX: 113; LEFT: 440px; POSITION:
absolute; TOP: 16px" runat="server"
Visible="False">Filter by CP:</asp:Label>

<asp:Label
id="lblselectedCP" style="Z-INDEX: 114; LEFT: 648px;
POSITION: absolute; TOP: 40px"
runat="server" Visible="False"></asp:Label>

<asp:TextBox
id="txtSelectedCP" style="Z-INDEX: 115; LEFT: 840px;
POSITION: absolute; TOP: 80px"
runat="server" Width="64px" Visible="False"></asp:TextBox>

<asp:Label
id="Label11" style="Z-INDEX: 116; LEFT: 848px; POSITION:
absolute; TOP: 56px" runat="server"
Visible="False">CP</asp:Label></form>

</body>

</HTML>

Nov 22 '05 #3
Hi Derek,

The problem is that when you click the button1, it is also a postback so
that the reverse update also get executed. Is possible to move
ReverseUpdate out of Form load and add it in the Save/Update button's Click?

Luke
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)

Nov 22 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
464
by: Derek | last post by:
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...
11
3460
by: Johnny | last post by:
I'm a rookie at C# and OO so please don't laugh! I have a form (fclsTaxCalculator) that contains a text box (tboxZipCode) containing a zip code. The user can enter a zip code in the text box and...
1
2061
by: Eugene Turin | last post by:
I'm writing a simple app that acts with simple DBF table via ODBCAdapter. I've got the idea of working with DataGrid, DataDet and DataAdapter. I connect to my Adapter DeleteCommand and AddComand....
8
4394
by: Johnny | last post by:
I'm a rookie at C# and OO so please don't laugh! I have a form (fclsTaxCalculator) that contains a text box (tboxZipCode) containing a zip code. The user can enter a zip code in the text box and...
1
1689
by: Machelle Chandler | last post by:
All, I'm trying to populate a datagrid with a data adapter that uses a stored procedure with a parameter. I get the below error when I run my code (as seen below). Any hints? If I delete...
1
1521
by: James | last post by:
I have an sp with paramaters like this: ALTER PROCEDURE dbo.SomeProc ( @SortBy varchar(50) = NULL @ShowComplete bit = 0 @StaffID int = NULL ) AS DECLARE @SQL varchar(2500) SET @SQL =
1
1431
by: Laura K | last post by:
I have a datagrid with a hyperlink field. It passes a parameter but I need it to pass three. I need two of the parameters to be querystrings that have already been passed to the page but I have...
6
4730
by: Jack | last post by:
I have the following: * An OLEDBCommand with command text "SELECT CAMPAIGN, DAY_OUT WHERE (CAMPAIGN LIKE '@campaign')" * A DataAdapter that point the select to the above command * A data grid...
1
8807
by: Mikey G | last post by:
Hi, I created a simple VB.NET 2003 application through Visual Studio that connects to a MySQL database and loads a table into a Dataset, and then displays that table information in a DataGrid on a...
3
2005
by: pjcraig | last post by:
This is driving me crazy! I have a form that a user will access from another form by selecting the item that they wish to view. When they open the new form, I pass through the id of the item they...
0
7199
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7074
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7322
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
7451
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5572
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
5000
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
3150
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
731
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
374
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.