473,669 Members | 2,420 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 2787
HTML (aspx)

<asp:datagrid id="DataGrid1" runat="server" AutoGenerateCol umns="False">
<Columns>
<asp:TemplateCo lumn HeaderText="Mon ">
<ItemTemplate >
<asp:TextBox id="TextBox1" runat="server" Width="30px" MaxLength="2"
AutoPostBack="F alse"></asp:TextBox><BR >
<asp:CompareVal idator id="CompareVali dator1" runat="server"
ControlToValida te="TextBox1" Operator="DataT ypeCheck" Type="Integer"
Font-Size="XX-Small">Numbers Only!</asp:CompareVali dator><BR>
<asp:RangeValid ator id="RangeValida tor1" runat="server"
ControlToValida te="TextBox1" Font-Size="XX-Small" MaximumValue="2 4"
MinimumValue="0 ">Must be between 0 - 24</asp:RangeValida tor>
</ItemTemplate>
</asp:TemplateCol umn>
<asp:TemplateCo lumn HeaderText="Tue s">
<ItemTemplate >
<asp:TextBox id="Textbox2" runat="server" AutoPostBack="F alse"
MaxLength="2" Width="30px"></asp:TextBox><br >
<asp:CompareVal idator id="Comparevali dator2" runat="server"
ControlToValida te="Textbox2" Operator="DataT ypeCheck" Type="Integer"
Font-Size="XX-Small">Numbers Only!</asp:CompareVali dator><br>
<asp:RangeValid ator id="Rangevalida tor2" runat="server"
ControlToValida te="Textbox2" Font-Size="XX-Small" MaximumValue="2 4"
MinimumValue="0 ">Must be between 0 - 24</asp:RangeValida tor>
</ItemTemplate>
</asp:TemplateCol umn>
<asp:TemplateCo lumn HeaderText="Wed ">
<ItemTemplate >
<asp:TextBox id="Textbox3" runat="server" AutoPostBack="F alse"
MaxLength="2" Width="30px"></asp:TextBox><br >
<asp:CompareVal idator id="Comparevali dator3" runat="server"
ControlToValida te="Textbox3" Operator="DataT ypeCheck" Type="Integer"
Font-Size="XX-Small">Numbers Only!</asp:CompareVali dator><br>
<asp:RangeValid ator id="Rangevalida tor3" runat="server"
ControlToValida te="Textbox3" Font-Size="XX-Small" MaximumValue="2 4"
MinimumValue="0 ">Must be between 0 - 24</asp:RangeValida tor>
</ItemTemplate>
</asp:TemplateCol umn>
<asp:TemplateCo lumn HeaderText="Thu rs">
<ItemTemplate >
<asp:TextBox id="Textbox4" runat="server" AutoPostBack="F alse"
MaxLength="2" Width="30px"></asp:TextBox><br >
<asp:CompareVal idator id="Comparevali dator4" runat="server"
ControlToValida te="Textbox4" Operator="DataT ypeCheck" Type="Integer"
Font-Size="XX-Small">Numbers Only!</asp:CompareVali dator><br>
<asp:RangeValid ator id="Rangevalida tor4" runat="server"
ControlToValida te="Textbox4" Font-Size="XX-Small" MaximumValue="2 4"
MinimumValue="0 ">Must be between 0 - 24</asp:RangeValida tor>
</ItemTemplate>
</asp:TemplateCol umn>
<asp:TemplateCo lumn HeaderText="Fri ">
<ItemTemplate >
<asp:TextBox id="Textbox5" runat="server" AutoPostBack="F alse"
MaxLength="2" Width="30px"></asp:TextBox><br >
<asp:CompareVal idator id="Comparevali dator5" runat="server"
ControlToValida te="Textbox5" Operator="DataT ypeCheck" Type="Integer"
Font-Size="XX-Small">Numbers Only!</asp:CompareVali dator><br>
<asp:RangeValid ator id="Rangevalida tor5" runat="server"
ControlToValida te="Textbox5" Font-Size="XX-Small" MaximumValue="2 4"
MinimumValue="0 ">Must be between 0 - 24</asp:RangeValida tor>
</ItemTemplate>
</asp:TemplateCol umn>
<asp:TemplateCo lumn HeaderText="Sat ">
<ItemTemplate >
<asp:TextBox id="Textbox6" runat="server" AutoPostBack="F alse"
MaxLength="2" Width="30px"></asp:TextBox><br >
<asp:CompareVal idator id="Comparevali dator6" runat="server"
ControlToValida te="Textbox6" Operator="DataT ypeCheck" Type="Integer"
Font-Size="XX-Small">Numbers Only!</asp:CompareVali dator><br>
<asp:RangeValid ator id="Rangevalida tor6" runat="server"
ControlToValida te="Textbox6" Font-Size="XX-Small" MaximumValue="2 4"
MinimumValue="0 ">Must be between 0 - 24</asp:RangeValida tor>
</ItemTemplate>
</asp:TemplateCol umn>
<asp:TemplateCo lumn HeaderText="Sun ">
<ItemTemplate >
<asp:TextBox id="Textbox7" runat="server" AutoPostBack="F alse"
MaxLength="2" Width="30px"></asp:TextBox><br >
<asp:CompareVal idator id="Comparevali dator7" runat="server"
ControlToValida te="Textbox7" Operator="DataT ypeCheck" Type="Integer"
Font-Size="XX-Small">Numbers Only!</asp:CompareVali dator><br>
<asp:RangeValid ator id="Rangevalida tor7" runat="server"
ControlToValida te="Textbox7" Font-Size="XX-Small" MaximumValue="2 4"
MinimumValue="0 ">Must be between 0 - 24</asp:RangeValida tor>
</ItemTemplate>
</asp:TemplateCol umn>
<asp:TemplateCo lumn HeaderText="Tot al">
<ItemTemplate >
<asp:Label id="lblTotal" runat="server"> 0</asp:Label>
</ItemTemplate>
</asp:TemplateCol umn>
<asp:ButtonColu mn Text="Sum" ButtonType="Pus hButton"
CommandName="SU M"></asp:ButtonColum n>
</Columns>
</asp:datagrid>

Codebehind (vb):

Dim ds As New DataSet("ds")

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArg s) 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("UserD BConnString"))
Dim adpt As New OleDbDataAdapte r("SELECT * FROM DUAL WHERE ROWNUM <=
1", conn) 'gets me a row quickly from Oracle!!
conn.Open()
adpt.Fill(ds)
DataGrid1.DataS ource = ds.Tables(0).De faultView
DataGrid1.DataB ind()
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).Co ntrols
If InStr(LCase(ctr l.GetType.ToStr ing), "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_ItemC ommand(ByVal source As Object, ByVal e As
System.Web.UI.W ebControls.Data GridCommandEven tArgs) Handles
DataGrid1.ItemC ommand
If e.CommandName = "SUM" Then
calcTotal(e.Ite m.ItemIndex)
End If
End Sub
"MSNEWS" <xx@nospam.co m> wrote in message
news:%2******** ********@tk2msf tngp13.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
3261
by: magister | last post by:
Hello, I have xml like this.... <test> <question>sdfsa</question> <section><question>43ga</question> <question>asdf</question> </test>
0
1076
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 net. It uses System.Windows.Forms.DataGrid.HitTestInfo myHitTest; The first question is, when I use this in my code, it compiles and works fine. But when I type... System.Windows.Forms.DataGrid and press the "." at the end of DataGrid, I don't...
3
4431
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 DataGrid object doesn't seem to have a any type of a selection changed type of event I can grab. THE QUESTION: Does anyone know how to determine when the selected row or set of rows within a datagrid has changed ??? This is driving me nuts !
6
1706
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 I tell that the user has reselected a different set of rows in a datagrid.
2
4326
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 how to use this code? please help! http://www.experts-exchange.com/Programming/Programming_Languages/C_Sharp/Q_20862953.html
2
17006
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 the columns of the data grid contains a DropDownlist. I managed to create this datagrid control as follows.
2
2325
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, Fax, Phone, Category). Put an Edit column at the end... Now what?! If you go into Edit mode -- you can only edit 5 cells -- not all the rest of the Record's fields...not enough!
3
1574
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 PageIndexChanged of the datagrid 'coz every time when the user change of page the app load again all data and another processes with the data even though I have load one dataset with the data for the datagrid..... the question is? What can I do to...
4
2279
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 combobox in a datagrid? Any other suggestions/articles on how to implement many-many relations in the frontend (which of course are 2 one-many relations)?
13
2473
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 them. In a plain vanilla DataGrid, when you click on the RowHeader, the appropriate row changes colors. I ASSUME this should be done in the Paint (or PaintText) override of the DataGridColumnStyle in question. My problem is that I don't know...
0
8465
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8383
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8809
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8588
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
7407
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
4206
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
2797
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2032
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1788
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 can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.