SitePoint Sponsor

User Tag List

Results 1 to 1 of 1
  1. #1
    SitePoint Evangelist Miguel61's Avatar
    Join Date
    Mar 2008
    Posts
    408
    Mentioned
    4 Post(s)
    Tagged
    0 Thread(s)

    Checkbox in GridView

    Hi all, hope in your help.

    If select in GV a check box from 1 row then you want all other rows in the GridView to be disabled leaving the current row enabled...
    I tried this code but not working ... can you help me?

    Code:
        protected void CheckBox1_CheckedChanged(object sender, EventArgs e)
        {
            CheckBox chkTest = (CheckBox)sender;
            GridViewRow GridView1 = (GridViewRow)chkTest.NamingContainer;
    
            if (chkTest.Checked)
            {
               GridView1.BackColor = System.Drawing.Color.Yellow;
            }
        }
    
    
        protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            if (e.Row.RowType == DataControlRowType.DataRow)
            {
                DropDownList DDL = (DropDownList)e.Row.FindControl("DDL");
    
                foreach (GridViewRow gvr in GridView1.Rows)
                {
                    if (((CheckBox)gvr.FindControl("chkSelect")).Checked)
                    {
                        DDL.Enabled = false;
                    }
                    else
                    {
                        DDL.Enabled = true;
                    }
                }
            }
        }

  2. #2
    SitePoint Mentor NightStalker-DNS's Avatar
    Join Date
    Jul 2004
    Location
    Cape Town, South Africa
    Posts
    2,880
    Mentioned
    48 Post(s)
    Tagged
    0 Thread(s)
    Hi

    You would probably want to do something like this with javascript and not server-side code. Your code above only checks on page load if it is checked or not to disable all others. So if nothing is checked by default, that would not work.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •