-----------------------------------------------------------
New Message on BDOTNET
-----------------------------------------------------------
From: PKSPMR
Message 1 in Discussion
Hi All,
I have a requirement for the grid to work with above mentioned criteria.
Here is an example:
Grid
Product Name<o:p></o:p>
Qty
>From Database<o:p></o:p>
TextBox for user input<o:p></o:p>
>From Database<o:p></o:p>
TextBox for user input<o:p></o:p>
>From Database<o:p></o:p>
TextBox for user input<o:p></o:p>
>From Database<o:p></o:p>
TextBox for user input<o:p></o:p>
<o:p> </o:p>
<o:p> </o:p>
Total<o:p></o:p>
running total of qty in a text box done by javascript.
I have 100 products. So I need to add paging and sorting functionality also.
Questions: When I add paging functionality, Total row gets created for
each and every page of gridview. I need it only in the last page, because I
want to get the running total quantity and check it against other textbox
total. How does sorting works.
I am using template field for total and javascript to do the running total.
since paging does postback trip to server, I am loosing what ever the I entered
in qty textboxes in 1st page of gridview, when I comeback to first page from
2nd or 3rd page.
I really need help in this. All my application pages need to have this
functionality. It is very major. Without figuring out this, I can't proceed. I
appreciate your response.
Here is the code. No code in codebehind files.
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="RunningTotal.aspx.cs"
Inherits="GridViewTest.RunningTotal" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Untitled Page</title>
<script type="text/javascript" language="javascript">
// This function should iterate through all the TextBoxes and get the values
function Add()
{
var obj = window.event.srcElement;
var tBox;
// clear the sum variable
var sum = 0;
if(obj.tagName == "INPUT" && obj.type == "text")
{
// Iterate through all the TextBoxes
tBox = document.getElementsByTagName("INPUT");
for(i = 0; i< (tBox.length - 2) ; i++)
{
if(tBox[i].type == "text")
{
// The Number function forces the JavaScript //to recognizes the
input as a number
var controlid = tBox[i].id;
if (! controlid.match("txtTotal"))
{
sum += Number(tBox[i].value);
}
}
}
}
// set the value in the total box
document.getElementById(controlid).innerText = sum;
}
</script>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False"
DataKeyNames="ProductID"
DataSourceID="SqlDataSource1" ShowFooter="True" Style="z-index:
100; left: 36px;
position: absolute; top: 247px" Width="488px" AllowPaging="True"
PageSize="4">
<Columns>
<asp:BoundField DataField="ProductID" HeaderText="ProductID"
ReadOnly="True" SortExpression="ProductID" />
<asp:TemplateField HeaderText="Product Name"
SortExpression="Name">
<ItemTemplate>
<asp:Label ID="Label1" runat="server" Text='<%#
Eval("Name") %>'></asp:Label>
</ItemTemplate>
<FooterTemplate>
<b>Total</b>
</FooterTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Price">
<FooterTemplate>
<asp:TextBox ID="txtTotal" runat="server"
BackColor="Beige" Font-Bold="True"
Font-Size="Larger" Enabled="False"></asp:TextBox>
</FooterTemplate>
<ItemTemplate>
<asp:TextBox ID="txtPrice" onChange="Add()"
runat="server" />
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="<%$ ConnectionStrings:HalloweenConnectionString %>"
SelectCommand="select top 8 ProductID, Name from
Products"></asp:SqlDataSource>
</div>
</form>
</body>
</html>
Thanks,
PK
-----------------------------------------------------------
To stop getting this e-mail, or change how often it arrives, go to your E-mail
Settings.
http://groups.msn.com/bdotnet/_emailsettings.msnw
Need help? If you've forgotten your password, please go to Passport Member
Services.
http://groups.msn.com/_passportredir.msnw?ppmprop=help
For other questions or feedback, go to our Contact Us page.
http://groups.msn.com/contact
If you do not want to receive future e-mail from this MSN group, or if you
received this message by mistake, please click the "Remove" link below. On the
pre-addressed e-mail message that opens, simply click "Send". Your e-mail
address will be deleted from this group's mailing list.
mailto:[EMAIL PROTECTED]