473,383 Members | 1,805 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,383 software developers and data experts.

Datagrid question

Hi

I have a datagrid with 8 Columns, columns called Monday - Sunday, and a
column called TOTAL. The Monday - Sunday columns are template columns with
a textbox inside. The TOTAL column is a label column.

When the user enteres numbers into the Monday - Sunday columns I want TOTAL
to add up all the columns on the current row.

I guess this needs to be done with client side vbscript? But I have no clue
where to start.

Also could somebody give me hints on how to validate by Monday - Sunday
columns so that they can only enter numbers between 0 and 24.

Thanks
Nov 18 '05 #1
1 2740
HTML (aspx)

<asp:datagrid id="DataGrid1" runat="server" AutoGenerateColumns="False">
<Columns>
<asp:TemplateColumn HeaderText="Mon">
<ItemTemplate>
<asp:TextBox id="TextBox1" runat="server" Width="30px" MaxLength="2"
AutoPostBack="False"></asp:TextBox><BR>
<asp:CompareValidator id="CompareValidator1" runat="server"
ControlToValidate="TextBox1" Operator="DataTypeCheck" Type="Integer"
Font-Size="XX-Small">Numbers Only!</asp:CompareValidator><BR>
<asp:RangeValidator id="RangeValidator1" runat="server"
ControlToValidate="TextBox1" Font-Size="XX-Small" MaximumValue="24"
MinimumValue="0">Must be between 0 - 24</asp:RangeValidator>
</ItemTemplate>
</asp:TemplateColumn>
<asp:TemplateColumn HeaderText="Tues">
<ItemTemplate>
<asp:TextBox id="Textbox2" runat="server" AutoPostBack="False"
MaxLength="2" Width="30px"></asp:TextBox><br>
<asp:CompareValidator id="Comparevalidator2" runat="server"
ControlToValidate="Textbox2" Operator="DataTypeCheck" Type="Integer"
Font-Size="XX-Small">Numbers Only!</asp:CompareValidator><br>
<asp:RangeValidator id="Rangevalidator2" runat="server"
ControlToValidate="Textbox2" Font-Size="XX-Small" MaximumValue="24"
MinimumValue="0">Must be between 0 - 24</asp:RangeValidator>
</ItemTemplate>
</asp:TemplateColumn>
<asp:TemplateColumn HeaderText="Wed">
<ItemTemplate>
<asp:TextBox id="Textbox3" runat="server" AutoPostBack="False"
MaxLength="2" Width="30px"></asp:TextBox><br>
<asp:CompareValidator id="Comparevalidator3" runat="server"
ControlToValidate="Textbox3" Operator="DataTypeCheck" Type="Integer"
Font-Size="XX-Small">Numbers Only!</asp:CompareValidator><br>
<asp:RangeValidator id="Rangevalidator3" runat="server"
ControlToValidate="Textbox3" Font-Size="XX-Small" MaximumValue="24"
MinimumValue="0">Must be between 0 - 24</asp:RangeValidator>
</ItemTemplate>
</asp:TemplateColumn>
<asp:TemplateColumn HeaderText="Thurs">
<ItemTemplate>
<asp:TextBox id="Textbox4" runat="server" AutoPostBack="False"
MaxLength="2" Width="30px"></asp:TextBox><br>
<asp:CompareValidator id="Comparevalidator4" runat="server"
ControlToValidate="Textbox4" Operator="DataTypeCheck" Type="Integer"
Font-Size="XX-Small">Numbers Only!</asp:CompareValidator><br>
<asp:RangeValidator id="Rangevalidator4" runat="server"
ControlToValidate="Textbox4" Font-Size="XX-Small" MaximumValue="24"
MinimumValue="0">Must be between 0 - 24</asp:RangeValidator>
</ItemTemplate>
</asp:TemplateColumn>
<asp:TemplateColumn HeaderText="Fri">
<ItemTemplate>
<asp:TextBox id="Textbox5" runat="server" AutoPostBack="False"
MaxLength="2" Width="30px"></asp:TextBox><br>
<asp:CompareValidator id="Comparevalidator5" runat="server"
ControlToValidate="Textbox5" Operator="DataTypeCheck" Type="Integer"
Font-Size="XX-Small">Numbers Only!</asp:CompareValidator><br>
<asp:RangeValidator id="Rangevalidator5" runat="server"
ControlToValidate="Textbox5" Font-Size="XX-Small" MaximumValue="24"
MinimumValue="0">Must be between 0 - 24</asp:RangeValidator>
</ItemTemplate>
</asp:TemplateColumn>
<asp:TemplateColumn HeaderText="Sat">
<ItemTemplate>
<asp:TextBox id="Textbox6" runat="server" AutoPostBack="False"
MaxLength="2" Width="30px"></asp:TextBox><br>
<asp:CompareValidator id="Comparevalidator6" runat="server"
ControlToValidate="Textbox6" Operator="DataTypeCheck" Type="Integer"
Font-Size="XX-Small">Numbers Only!</asp:CompareValidator><br>
<asp:RangeValidator id="Rangevalidator6" runat="server"
ControlToValidate="Textbox6" Font-Size="XX-Small" MaximumValue="24"
MinimumValue="0">Must be between 0 - 24</asp:RangeValidator>
</ItemTemplate>
</asp:TemplateColumn>
<asp:TemplateColumn HeaderText="Sun">
<ItemTemplate>
<asp:TextBox id="Textbox7" runat="server" AutoPostBack="False"
MaxLength="2" Width="30px"></asp:TextBox><br>
<asp:CompareValidator id="Comparevalidator7" runat="server"
ControlToValidate="Textbox7" Operator="DataTypeCheck" Type="Integer"
Font-Size="XX-Small">Numbers Only!</asp:CompareValidator><br>
<asp:RangeValidator id="Rangevalidator7" runat="server"
ControlToValidate="Textbox7" Font-Size="XX-Small" MaximumValue="24"
MinimumValue="0">Must be between 0 - 24</asp:RangeValidator>
</ItemTemplate>
</asp:TemplateColumn>
<asp:TemplateColumn HeaderText="Total">
<ItemTemplate>
<asp:Label id="lblTotal" runat="server">0</asp:Label>
</ItemTemplate>
</asp:TemplateColumn>
<asp:ButtonColumn Text="Sum" ButtonType="PushButton"
CommandName="SUM"></asp:ButtonColumn>
</Columns>
</asp:datagrid>

Codebehind (vb):

Dim ds As New DataSet("ds")

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
'Put user code to initialize the page here

If Not IsPostBack() Then
fillGrid()
End If

End Sub

Private Sub fillGrid()
Dim conn As New OleDbConnection(Session("UserDBConnString"))
Dim adpt As New OleDbDataAdapter("SELECT * FROM DUAL WHERE ROWNUM <=
1", conn) 'gets me a row quickly from Oracle!!
conn.Open()
adpt.Fill(ds)
DataGrid1.DataSource = ds.Tables(0).DefaultView
DataGrid1.DataBind()
conn.Close()
End Sub

Private Sub calcTotal(ByVal intRow As Integer)
Dim dgi As DataGridItem = DataGrid1.Items(intRow)
Dim intSum As Integer = 0
Dim ctrl As Control
Dim tb As TextBox
Dim i As Integer = 0

For i = 0 To dgi.Cells.Count - 1
For Each ctrl In dgi.Cells(i).Controls
If InStr(LCase(ctrl.GetType.ToString), "textbox") <> 0 Then
tb = CType(ctrl, TextBox)
If Not tb.Text = "" Then
intSum += CInt(tb.Text)
End If
End If
Next ctrl
Next i

Dim lbl As Label = dgi.FindControl("lblTotal")
lbl.Text = CStr(intSum)

End Sub

Private Sub DataGrid1_ItemCommand(ByVal source As Object, ByVal e As
System.Web.UI.WebControls.DataGridCommandEventArgs ) Handles
DataGrid1.ItemCommand
If e.CommandName = "SUM" Then
calcTotal(e.Item.ItemIndex)
End If
End Sub
"MSNEWS" <xx@nospam.com> wrote in message
news:%2****************@tk2msftngp13.phx.gbl...
Hi

I have a datagrid with 8 Columns, columns called Monday - Sunday, and a
column called TOTAL. The Monday - Sunday columns are template columns
with
a textbox inside. The TOTAL column is a label column.

When the user enteres numbers into the Monday - Sunday columns I want
TOTAL
to add up all the columns on the current row.

I guess this needs to be done with client side vbscript? But I have no
clue
where to start.

Also could somebody give me hints on how to validate by Monday - Sunday
columns so that they can only enter numbers between 0 and 24.

Thanks

Nov 18 '05 #2

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

Similar topics

2
by: magister | last post by:
Hello, I have xml like this.... <test> <question>sdfsa</question> <section><question>43ga</question> <question>asdf</question> </test>
0
by: Randy | last post by:
Hello, I have two questions... I have a datagrid. I'm capturing the cell via HitTestInfo. The first question is fairly simple. I'm using an example of how to capture the row/column I found on the...
3
by: BBFrost | last post by:
Ok, I know how to count the number of selected datagrid rows using the code below. What has me stumped is how to determine when the selected rows within a datagrid have been changed. The...
6
by: BBFrost | last post by:
I'm using Net 1.1 (2003) SP1 & Windows 2000 Here's the issue ... Rows 12 thru 24 are selected in a datagrid. The user now unselects rows 12 thru 24 and selects rows 45 thru 70 ??? How can...
2
by: pei_world | last post by:
I want to implement a key hit with enter to dropdown a combobox that is in the datagrid. in this case I need to override its original behaviours. I found some codes from the web. Does anyone know...
2
by: Dominic | last post by:
Hi guys, I'm not sure if this question belongs to FAQ, but I couldn't find a concrete answer. I created a Datagrid control using ItemTemplate, but it's NOT a in-place editing datagrid. One of...
2
by: Sky | last post by:
Hello: Another question about trying to wring functionality from a DataGrid... Have a DB table of "Contacts" -- 14 or more fields per record Show in datagrid -- but only 5 columns (First,Last,...
3
by: Danky | last post by:
Hello Masters! Anyone can help me with the datagrid, well, the app load a lot of data from DB and it show on the datagrid, and well, I need to allow paging and.... the issue is with the event...
4
by: Jan Nielsen | last post by:
Hi all I'm a former Access developer who would like to implement a many-to-many relation in about the same way you do in Access: With a subform and a combo box. Is it possible to use a...
13
by: pmcguire | last post by:
I have a DataGrid control for which I have also created several new extended DataGridColumnStyles. They behave pretty nicely, but I can't figure out how to implement Selected Item formatting for...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.