Click here to Skip to main content
15,905,877 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Dear All,

am working on ASP.NET , C#, SQLSERVER 2005.

on my webpage i have gridview with checkboxes and 3 columns in gridveiw,,,, below this gridview i have submit button... When I select one Checkbox and click on submit button.

On Next Page Checkbox Selected Value must be displayed in label.


Please help me friends

Thanks for ever
Posted
Comments
CodeBlack 10-Oct-13 3:04am    
are you able to bind grid with checkbox ?

C#
protected void gvrecords_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            CheckBox headerchk = (CheckBox)gvrecords.HeaderRow.FindControl("chkheader");
            CheckBox childchk = (CheckBox)e.Row.FindControl("chkSelect");
            childchk.Attributes.Add("onclick", "javascript:Selectchildcheckboxes('" + headerchk.ClientID + "')");
        }
    }
    protected void UpdateSupplyLed(object sender, EventArgs e)
    {
        double total = 0;
        CheckBox chkSampleStatus = sender as CheckBox;
        bool sample = chkSampleStatus.Checked;
        GridViewRow row = chkSampleStatus.NamingContainer as GridViewRow;
        foreach (GridViewRow gvrow in gvrecords.Rows)
        {
            CheckBox chk = (CheckBox)gvrow.FindControl("chkSelect");
            CheckBox headerchk = (CheckBox)gvrecords.HeaderRow.FindControl("chkheader");
            if (headerchk != null & headerchk.Checked)
            {
                total += Convert.ToDouble(gvrecords.DataKeys[gvrow.RowIndex].Value.ToString());
 
            }
            else if (chk != null & chk.Checked)
            {
                total += Convert.ToDouble(gvrecords.DataKeys[gvrow.RowIndex].Value.ToString());

            }
        }
        lbltotal.Text = Convert.ToString( total);
    }
    protected void btnsave_Click(object sender, EventArgs e)
    {
       
        objsupplyPL.username = Session["username"].ToString();
        objsupplyPL.indentid = Convert.ToInt64(hdnunique.Value.Trim());

        foreach (GridViewRow gvrow in gvrecords.Rows)
        {
            CheckBox chk = (CheckBox)gvrow.FindControl("chkSelect");
            if (chk != null & chk.Checked)
            {
                objsupplyPL.grno = gvrow.Cells[13].Text.ToString();               
                objsupplyBAL.InsertFeedPaymentDetailswithgrno(objsupplyPL);                
            }
        }
    
        objsupplyPL.totalamount =Convert.ToDouble( lbltotal.Text.ToString());
        objsupplyPL.paymenttype = ddlypaymenttype.SelectedItem.Text;
        objsupplyPL.bankdetails = Convert.ToInt32(ddlbankaccount.SelectedValue.ToString());
        objsupplyPL.chequenumber = txtcheque.Text.ToString() == "" ? null : txtcheque.Text.ToString();
        objsupplyPL.rtgs = txtRtgs.Text.ToString() == "" ? 0 : Convert.ToDouble(txtRtgs.Text.ToString());
        objsupplyBAL.InsertFeedPaymentDetailswithgrno1(objsupplyPL);





        grid();
        clear();

       
    }
 
Share this answer
 
v2
Set AutoPostback property of your grid checkbox to true and create selected index changed event of your checkbox and store the selected item in Session. Now when you go to the next page you can refer selected value from session. Find below code sample for the same kind of functionality :

ASPX Code :
XML
<asp:GridView runat="server" ID="gridMain" AutoGenerateColumns="False" OnRowDataBound="gridMainRowDataBound">
        <Columns>
            <asp:BoundField DataField="EmployeeName" HeaderText="Name" />
            <asp:TemplateField>
                <ItemTemplate>
                    <asp:CheckBoxList runat="server" ID="checkDivisions" AutoPostBack="True" OnSelectedIndexChanged="divisonChanged"/>                </ItemTemplate>
            </asp:TemplateField>
        </Columns>
    </asp:GridView>



ASPX.cs Code :

C#
public partial class About : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                this.BindGrid();
            }
        }

        private void BindGrid()
        {
            var empList = new List<Employee>();
            for (var i = 0; i < 5; i++)
            {
                var employee = new Employee
                                   {
                                       EmployeeName = "Name_" + i,
                                       Divisions =
                                           new List<Division>
                                               {
                                                   new Division
                                                       {
                                                           DivisionName = "A",
                                                           DivisonID = "1"
                                                       },
                                                   new Division
                                                       {
                                                           DivisionName = "B",
                                                           DivisonID = "2"
                                                       },
                                                   new Division
                                                       {
                                                           DivisionName = "C",
                                                           DivisonID = "3"
                                                       }
                                               }
                                   };

                empList.Add(employee);
            }

            this.gridMain.DataSource = empList;
            this.gridMain.DataBind();
        }

        protected void gridMainRowDataBound(object sender, GridViewRowEventArgs e)
        {
            var divisonList = e.Row.Cells[1].FindControl("checkDivisions") as CheckBoxList;

            if (divisonList != null)
            {
                divisonList.DataSource = DataBinder.Eval(e.Row.DataItem, "Divisions");
                divisonList.DataTextField = "DivisionName";
                divisonList.DataValueField = "DivisonID";
                divisonList.DataBind();
            }
        }

        protected void divisonChanged(object sender, EventArgs e)
        {
            Session["LastSelectedItem"] = ((ListControl)sender).SelectedItem.Text;
        }
    }

    /// <summary>
    /// The empl.
    /// </summary>
    public class Employee
    {
        public string EmployeeName { get; set; }

        public List<Division> Divisions { get; set; }
    }

    /// <summary>
    /// The empl 2.
    /// </summary>
    public class Division
    {
        public string DivisionName { get; set; }

        public string DivisonID { get; set; }
    }
 
Share this answer
 
v2
create a link button
in this
<asp:linkbutton id="LinkButton1" runat="server" postbackurl="<%#" ~="" guest="" default.aspx?id="+Eval(" uniqueid")="" %&gt;"="" xmlns:asp="#unknown">Add To Cart
///////////////////////////////////////////////////////////////////
then
on next page you can retrieve this value on labelid on page load like this

Label3.Text = Request.QueryString["id"];

try and let me know
 
Share this answer
 

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