This is a migrated thread and some comments may be shown as answers.

Databinding a textbox

1 Answer 116 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Michael
Top achievements
Rank 1
Michael asked on 04 Jan 2012, 08:28 PM
Made a mistake in the title, I meant CheckBox


Hello. 

I have a boolean value in a table that I would like to have the user edit by clicking a checkbox in a row of data. The GridCheckBoxColumn would be perfect but for some reason it cannot be edited. 

I made a checkbox in a template column and I can databind it to show the existing value, but I am struggling with having the value save back do the database when changed. What is the most simple way to achieve this, while using AJAX so the page does not reload? 

Is there any way to put the GridCheckBoxColumn in edit mode like when the EditCommand button is clicked? 

Thanks

1 Answer, 1 is accepted

Sort by
0
Michael
Top achievements
Rank 1
answered on 04 Jan 2012, 09:45 PM
Solved the issue with

        protected void chkComplete_changed(object sender, EventArgs e)
        {
            CheckBox chk = (CheckBox)sender;
            bool status = chk.Checked;
            GridDataItem item = (GridDataItem)chk.NamingContainer;
            string keyvalue = item.GetDataKeyValue("ID").ToString();


            SqlDataSource1.UpdateCommand = "UPDATE form SET COMPLETE = '" + status + "' WHERE ID = " + keyvalue;
            SqlDataSource1.Update();
            RadGrid1.DataBind();
            RadGrid1.DataSource = SqlDataSource1;                
        }

Where chkComplete_changed is the event when the checkbox status changes
Tags
Grid
Asked by
Michael
Top achievements
Rank 1
Answers by
Michael
Top achievements
Rank 1
Share this question
or