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

Update Grid after check box is checked

1 Answer 61 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Najid Hanif
Top achievements
Rank 2
Najid Hanif asked on 07 Aug 2012, 04:44 AM
Hi, My grid will contain check boxes as the only editable items. Is there a way for a user to just check the check boxes and automatically update the record? (Without an edit / update button)

Thanks

1 Answer, 1 is accepted

Sort by
0
Accepted
Jayesh Goyani
Top achievements
Rank 2
answered on 07 Aug 2012, 05:31 AM
Hello,

<telerik:RadGrid ID="RadGrid1" runat="server" AutoGenerateColumns="false" OnNeedDataSource="RadGrid1_NeedDataSource"
           OnItemCommand="RadGrid1_ItemCommand">
           <MasterTableView DataKeyNames="ID">
               <Columns>
                   <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" Text='<%# Eval("Name") %>'></asp:TextBox>
                       </ItemTemplate>
                   </telerik:GridTemplateColumn>
               </Columns>
           </MasterTableView>
       </telerik:RadGrid>
protected void RadGrid1_NeedDataSource(object sender, GridNeedDataSourceEventArgs e)
    {
        dynamic data = new[] {
                new { ID = 1, Name ="Name1"},
                new { ID = 2, Name = "Name2"},
                new { ID = 3, Name = "Name3"}
            };
 
 
        RadGrid1.DataSource = data;
    }
    protected void RadGrid1_ItemCommand(object sender, GridCommandEventArgs e)
    {
         
    }
    protected void CheckBox1_CheckedChanged(object sender, EventArgs e)
    {
// perform Update operation here
        CheckBox CheckBox1 = sender as CheckBox;
        GridDataItem item = CheckBox1.NamingContainer as GridDataItem;
        TextBox TextBox1 = item.FindControl("TextBox1") as TextBox;
 
        // get Data Key
        string strId = item.GetDataKeyValue("ID").ToString();
    }


Thanks,
Jayesh Goyani
Tags
Grid
Asked by
Najid Hanif
Top achievements
Rank 2
Answers by
Jayesh Goyani
Top achievements
Rank 2
Share this question
or