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

Updated selected rows

4 Answers 48 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Edd
Top achievements
Rank 1
Edd asked on 25 Nov 2013, 05:31 PM
I have a GridTemplateColumn that has a checkbox as a item template.
How can i update a column say "ClassNo" with a value in a textbox on a button click.
Any idea or work around
Thank you

4 Answers, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 26 Nov 2013, 05:11 AM
Hi Edd,

I guess you are selecting the row using CheckBox inside the GridTemplate column and that a TextBox and Button is outside the RadGrid. I suppose, on the selected row you want to update the value of column with TextBox value. Please try the following code snippet.

ASPX:
<telerik:RadGrid ID="RadGrid1" runat="server" AllowMultiRowSelection="true">
    <MasterTableView >
        <Columns>          
            <telerik:GridBoundColumn DataField="ClassNo" HeaderText="ClassNo" UniqueName="ClassNo" />        
            <telerik:GridTemplateColumn UniqueName="CheckBoxTemplateColumn">
                <ItemTemplate>
                    <asp:CheckBox ID="CheckBox1" runat="server" OnCheckedChanged="ToggleRowSelection"
                        AutoPostBack="True" />
                </ItemTemplate>
            </telerik:GridTemplateColumn>
        </Columns>
    </MasterTableView>
</telerik:RadGrid>
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
<asp:Button ID="UpdateBtn" runat="server" Text="Update" OnClick="UpdateBtn_Click" />

C#:
protected void ToggleRowSelection(object sender, EventArgs e)
 {
    //Select the Checked Row
    ((sender as CheckBox).NamingContainer as GridItem).Selected = (sender as CheckBox).Checked;
 }
 
protected void UpdateBtn_Click(object sender, EventArgs e)
 {
    var key = string.Empty;
    string text = TextBox1.Text;
    foreach (GridDataItem item in RadGrid1.SelectedItems)
    {         
        key = item.ItemIndex.ToString(); // Index of the Selected row
        item["ClassNo"].Text = text;
    }
 }

Thanks,
Princy
0
Edd
Top achievements
Rank 1
answered on 26 Nov 2013, 05:25 PM
please it updates it just on the client side.
How can i update it on the server side
0
Princy
Top achievements
Rank 2
answered on 27 Nov 2013, 04:37 AM
Hi Edd,

 I guess you want to make the changes into DB. Please try the following code snippet in the button click.

C#:
protected void UpdateBtn_Click(object sender, EventArgs e)
 {
    var key = string.Empty;
    string text= TextBox1.Text; 
    foreach (GridDataItem item in RadGrid1.SelectedItems)
    {       
        key = item.GetDataKeyValue("ID").ToString();    
       // Your code to Update to DB set ClassNo=text, where id=key
    }  
    RadGrid1.Rebind();      
 }


Thanks,
Princy
0
Edd
Top achievements
Rank 1
answered on 27 Nov 2013, 06:31 PM
Thank you it worked perfectly for me
Tags
Grid
Asked by
Edd
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Edd
Top achievements
Rank 1
Share this question
or