1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

How can set Checkbox Value From Database?

Discussion in 'C#' started by raspms, Mar 20, 2012.

  1. #1
    hello,
    i am doing project using asp.net with c#.in that one form is there named as menuform.their is many fields like status ,commentallow ,manuname etc..
    Also i have one database tabel in that i take status,comment as bit database.
    Now i want to suppose edit the record from gridview then i m calling on method named as show().
    In that i featched all gridview row data to that particular form ..all fields are featch but only status and commentallow which are the checkbox are not taken a value..
    can u tell me how can i set database value to checkbox means if status is true then checkbox must be checked(marked) automatically...otherwise it is uncheched...
    my show() is like this
    private void show()
    {
    try
    {
    con.Open();
    string query = "Select MenuName,MenuTitle,MenuSide,MenuStatus,MenuKeywords,MenuMetatag From tbl_MainMenu Where MenuId='" + Request.QueryString["Id"] + "' ";
    SqlCommand cmd = new SqlCommand(query, con);
    SqlDataReader dr = cmd.ExecuteReader();
    while (dr.Read())
    {
    txtmenuname.Text = dr[0].ToString();
    txtmenutitle.Text = dr[1].ToString();
    drpmenuside.Text = dr[2].ToString();
    drpmenustatus.Text = dr[3].ToString();
    txtkeywords.Text = dr[4].ToString();
    txtmetatag.Text = dr[5].ToString();
    chkstatus.Checked.ToString() = dr[6].ToString();
    chkcomment.Checked.ToString() = dr[7].ToString();
    }
    con.Close();
    }
    catch (Exception ex)
    {
    throw ex;
    }
    }
    SEMrush
     
    raspms, Mar 20, 2012 IP
    SEMrush
  2. geekstrack

    geekstrack Member

    Messages:
    71
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    36
    #2
    you can use 0,1 in your database just add a column with a int value, 0 for uncheck and 1 for check and by default at the time of inserting the details in database what you want it should be checked or unchecked in insert query pass 0 or 1 as per your condition.
    after selecting check its is 0 or 1 if it is 0 then checkbox.checked is false else true. and if you want user can change it values then on checked change event update database with 0 or 1...

    More from .Net
     
    geekstrack, Apr 22, 2012 IP