Click here to Skip to main content
15,919,132 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Here is my aspx code for GridView:

<asp:GridView ID="GridView1" ShowFooter="true" OnRowDataBound="GridView1_RowDataBound" runat="server" AutoGenerateColumns="False" DataKeyNames="korisnikID" DataSourceID="SqlDataSource1" Height="320px" Width="763px" CellPadding="4" Font-Names="Calibri" ForeColor="#333333" HorizontalAlign="Center" font-size="Medium" GridLines="None" CssClass="auto-style9" >

                <asp:Label ID="Label2" runat="server" Text="Вкупно сума за плаќање"></asp:Label>


        <asp:TemplateField HeaderText="Должи" HeaderStyle-Width="100px">
<asp:Label ID="lblListPrice" runat="server" Text='<%# int.Parse(Eval("Должи").ToString())%>'/> </Label>

                <asp:Label ID="lblTotal" runat="server" Text=""></asp:Label>
             <asp:TemplateField HeaderText="Означи за плаќање">
                    <asp:CheckBox ID="CheckBox1"  runat="server" onclick="javascript: DisableButton()"/>


And Aspx.cs code:
  protected void Button2_Click(object sender, EventArgs e)
            DataTable dt = new DataTable();
            dt.Columns.Add("Корисник", typeof(string));
            dt.Columns.Add("Износ", typeof(int));
            dt.Columns.Add("Побарува", typeof(int));
            dt.Columns.Add("Должи", typeof(int));

 SqlConnection sqlConn = new SqlConnection(Web.GetConfigValue("proekt1"));
            CheckBox ch;
            string fakturi = "";
            foreach (GridViewRow row in GridView1.Rows)
                int n = row.RowIndex;               
                ch = (CheckBox)row.FindControl("CheckBox1");
                if (ch.Checked == true)
                    Label lblCol1 = row.FindControl("lbliznos") as Label;
                    Label lblCol2 = row.FindControl("lblpobaruva") as Label;
                    Label lblCol3 = row.FindControl("lblListPrice") as Label;
                    if (lblCol1 != null && lblCol2 != null && lblCol3 != null)
                        int val1 = int.Parse(lblCol1.Text);
                        int val2 = int.Parse(lblCol2.Text);
                        int val3 = int.Parse(lblCol3.Text);
                        lblCol2.Text = (val2 + val3).ToString();
                        lblCol3.Text = (val3 * 0).ToString();
                    DataRow r = dt.NewRow();
                    r["Корисник"] = Web.SessionUser.Naziv.ToString(); //row.Cells[1].Text;
                    Label name2 = (Label)GridView1.Rows[n].Cells[3].FindControl("lbliznos");
                    r["Износ"] = name2.Text;
                    Label name = (Label)GridView1.Rows[n].Cells[5].FindControl("lblpobaruva");
                    r["Побарува"] = name.Text;
                    Label name1 = (Label)GridView1.Rows[n].Cells[6].FindControl("lblListPrice");
                    r["Должи"] = name1.Text;
                    if (fakturi != "") fakturi += ",";
                    fakturi += row.Cells[0].Text;
            Session["platiltabela"] = dt;
            Session["fakturi"] = fakturi;

  protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
            if (e.Row.RowType == DataControlRowType.DataRow)
                CheckBox chk = (CheckBox)e.Row.FindControl("CheckBox1");
                Label name1 = (Label)e.Row.FindControl("lblListPrice");
                if (name1.Text == "0")
                    chk.Enabled = false;
                    chk.Enabled = true;
                if (chk.Checked == false)
                    Button2.Enabled = false;
                else { Button2.Enabled = true; }
Updated 28-Apr-14 2:51am
ZurdoDev 28-Apr-14 9:14am    
Where are you stuck? There are many examples online including this site.
R.Elena 28-Apr-14 9:17am    
I tried with javascript to get checked cells and it work, But won't pass to another page

I use this script

<script type="text/javascript">
$(function () {
$("input[type=checkbox]").change(function () {
var totalPrice = 0, ctlPrice;
$('#GridView1 tr').each(function () {
if ($(this).find('input:checkbox').attr("checked")) {
ctlPrice = $(this).find('[id$= lblListPrice]');
totalPrice += parseFloat(ctlPrice.text().replace(/[^\d\.]/g, ''));
$("#<%=GridView1.ClientID %> [id*=lblTotal]").text(totalPrice.toFixed(2));

How can i store lblTotal in querystring in js and pass to another page?
ZurdoDev 28-Apr-14 9:23am    
To pass to another page you either need to put it into a cookie which the other page looks for, or the querystring or the session. It's up to you and partially depends on how you are getting to the next page.
R.Elena 28-Apr-14 9:26am    
Yes I know. But I am new in javascript. Can you gave me an example for passing value of lbltotal to another page?
ZurdoDev 28-Apr-14 9:27am    
Again, there are many ways to do it. You need to decide which way to do it. How are you getting to the next page now?

1 solution

why you use js, you also use many other, if you have value in label then try this....
for source page---
Session["Value"] = lblvalue.Text;
for target page--
string Value= Session["Value"]
Share this answer
R.Elena 29-Apr-14 2:36am    
And what about sum of checked cells in a column? What to use?
R.Elena 29-Apr-14 3:17am    
I resolve the problem :)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900