none
select the row using checkbox RRS feed

  • Question

  •  

    Hi..

       Iam using gridview for displaying the data.I gave the first column for checkbox.my requirement is while i check the checkboxes i want to select that row...........can  u help!

    Friday, October 5, 2007 8:29 AM

Answers

  • Hi, Santhosh

     

    You need to synchronize the state of the checkbox and the corresponding row. As you know that when you click a new row or cell in the DataGridView, the former selected rows get disselected automatically. To prevent this you have to change the behavior of the DataGridView, which tends to be quite problematic.

     

    A workaround is to change the Style of the rows that have been checked. For example, change the background color of the row by the DataGridViewRow.DefaultCellStyle.BackColor. Thus you only need to synchronize the state in one direction, which can be controlled easier.

     

    Best Regards

    Chunsheng Tang

    Monday, October 8, 2007 9:42 AM

All replies

  • Generally you do something like this

     

    Code Block

    this.dataGridView1.Rows[dataGridView1.CurrentRow.Index].Cells["column1"].Value.ToString().Trim();

     

     

     

    But you can also add an event like this

     

    Code Block

    private void DataGridView1_CellEndEdit(object sender, DataGridViewCellEventArgs e)

    {

    //

    }

     

     

     

    Saturday, October 6, 2007 2:57 AM
  • Hi, Santhosh

     

    You need to synchronize the state of the checkbox and the corresponding row. As you know that when you click a new row or cell in the DataGridView, the former selected rows get disselected automatically. To prevent this you have to change the behavior of the DataGridView, which tends to be quite problematic.

     

    A workaround is to change the Style of the rows that have been checked. For example, change the background color of the row by the DataGridViewRow.DefaultCellStyle.BackColor. Thus you only need to synchronize the state in one direction, which can be controlled easier.

     

    Best Regards

    Chunsheng Tang

    Monday, October 8, 2007 9:42 AM
  • # region Repeater Item DataBound
        protected void rDefectDetail_ItemDataBound(object sender, RepeaterItemEventArgs e)
        {
            if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
            {
                DataRowView row = e.Item.DataItem as DataRowView;
                CheckBox chkDelete = e.Item.FindControl("chkDelete") as CheckBox;
                chkDelete.Attributes.Add("PROJECT_CODE", row["PROJECT_CODE"].ToString());
                chkDelete.Attributes.Add("CLIENT_CODE", row["CLIENT_CODE"].ToString());
            }
        }
        #endregion

     

    I do this repeater hope this is useful for u..
    Wednesday, October 24, 2007 6:36 AM
  •     # region Repeater Item DataBound
        protected void rDefectDetail_ItemDataBound(object sender, RepeaterItemEventArgs e)
        {
            if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
            {
                DataRowView row = e.Item.DataItem as DataRowView;
                CheckBox chkDelete = e.Item.FindControl("chkDelete") as CheckBox;
                chkDelete.Attributes.Add("DEFECT_ID", row["DEFECT_ID"].ToString());
                chkDelete.Attributes.Add("PROJECT_CODE", row["PROJECT_CODE"].ToString());
                chkDelete.Attributes.Add("CLIENT_CODE", row["CLIENT_CODE"].ToString());
            }
        }
        #endregion

     

    I done with repeater hope this is useful for u..

    Wednesday, October 24, 2007 6:37 AM