add

Monday, 12 August 2013

Binding the data into Gridview in asp.net C#


 private void getdata()
    {
        string _SelectedValues = string.Empty;
        string s = "select query'";
        SqlDataAdapter da = new SqlDataAdapter(s, con);
        DataSet ds = new DataSet();
        da.Fill(ds);
        grdstore.DataSource = ds;
        grdstore.DataBind();
        if (grdstore.Rows.Count > 0)
        {
            for (int p = 0; p < grdstore.Rows.Count; p++)
            {
                CheckBox chkselect = (CheckBox)grdstore.Rows[p].Cells[0].FindControl("chkboxlst");
                chkselect.Checked = true;
          
                //chkselect.CheckedChanged += new EventHandler(chkboxlst_CheckedChanged);
                for (int i = 0; i < grdstore.Rows.Count; i++)
                {
                    CheckBox chkbox = (CheckBox)grdstore.Rows[i].Cells[0].FindControl("chkboxlst");
                    if (chkbox.Checked)
                    {
                        Label lblid = (Label)grdstore.Rows[i].Cells[1].FindControl("lbl");
                        if (_SelectedValues != string.Empty)
                            _SelectedValues += ",";
                        _SelectedValues += "" + lblid.Text + "";

                    }
                }

            }

No comments:

Post a Comment