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

Click checkbox - save the row

3 Answers 70 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Jeff Bradshaw
Top achievements
Rank 1
Jeff Bradshaw asked on 24 Jan 2012, 08:49 PM
I want to have a grid that has a couple of fields and one will be a checkbox that the user can check to say they want to include the record. Because of the way our customers work, I need to do this without a save button. So I want to have an autopostback when the box is checked and update that record in the database.

How can I do this?

TIA - Jeff.

3 Answers, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 25 Jan 2012, 05:42 AM
Hello,

One suggestion is you can try to save the record on CheckedChanged event of CheckBox and set AutoPostback property of CheckBox as true.

Thanks,
Princy.
0
Jeff Bradshaw
Top achievements
Rank 1
answered on 25 Jan 2012, 02:00 PM
That's what I was planning on doing. But how do I know which record to update? Typically I've done it where there's a hidden field that has the record ID but I can't figure out how to 'find' that variable in the CheckChanged.
0
Jayesh Goyani
Top achievements
Rank 2
answered on 27 Jan 2012, 02:29 PM
Hello Jeff,

<Columns>
                       <telerik:GridBoundColumn DataField="ID" UniqueName="ID" HeaderText="ID">
                       </telerik:GridBoundColumn>
                       <telerik:GridTemplateColumn>
                       <ItemTemplate>
                           <asp:CheckBox ID="CheckBox1" runat="server" OnCheckedChanged="CheckBox1_CheckedChanged"
                               AutoPostBack="true" />
                       </ItemTemplate>
                   </telerik:GridTemplateColumn>
                    <telerik:GridTemplateColumn>
                       <ItemTemplate>
                           <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
                       </ItemTemplate>
                   </telerik:GridTemplateColumn>
 
                   </Columns>
protected void CheckBox1_CheckedChanged(object sender, EventArgs e)
    {
        CheckBox CheckBox1 = sender as CheckBox;
        GridDataItem item = CheckBox1.NamingContainer as GridDataItem;
        //using datakey
        //  <MasterTableView DataKeyNames="ID" Name="Parent">
        string str1 = item.GetDataKeyValue("ID").ToString();
 
 
        // using column
 
        string str2 = item["ID"].Text;
 
        string str3 = (item.FindControl("TextBox1") as TextBox).Text;
 
 
        // perform your DB opertaion here
    }


Thanks,
Jayesh Goyani
Tags
Grid
Asked by
Jeff Bradshaw
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Jeff Bradshaw
Top achievements
Rank 1
Jayesh Goyani
Top achievements
Rank 2
Share this question
or