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

Need help with Grid

3 Answers 49 Views
Grid
This is a migrated thread and some comments may be shown as answers.
nhaydon
Top achievements
Rank 1
nhaydon asked on 26 Aug 2011, 02:26 PM
I am trying to display a grid with 3 columns. 2 of the columns are updateable. The problem I am having is when the client does a batch update, I dont want to update every record from the grid to the database. I only want to process just the changed records/cells. It is almost like a hybrid Excel grid project demo and the Telerik ClientEditBatchUpdates demo. I dont want the user to have to click edit on every row so that is why I am using the Excel like demo. Anyone have any experience with this?

3 Answers, 1 is accepted

Sort by
0
Jayesh Goyani
Top achievements
Rank 2
answered on 26 Aug 2011, 07:56 PM
Hello,

for normal mode.

<MasterTableView DataKeyNames="ID,Name">
        <Columns>
            <telerik:GridBoundColumn DataField="ID" UniqueName="ID" HeaderText="ID"></telerik:GridBoundColumn>
            <telerik:GridTemplateColumn DataField="Name" UniqueName="Name" HeaderText="Name">
            <ItemTemplate>
                <asp:TextBox ID="TextBox1" runat="server" Text='<%# Eval("Name") %>'></asp:TextBox>
            </ItemTemplate>
            </telerik:GridTemplateColumn>
        </Columns>
    </MasterTableView>
protected void Button1_Click(object sender, EventArgs e)
        {
            foreach (GridDataItem item in RadGrid1.Items)
            {
                string OldName = item.GetDataKeyValue("Name").ToString();
                string newName = (item.FindControl("TextBox1") as TextBox).Text.Trim();
 
                if (OldName != newName)
                {
                    // Perform DB operation here
                }
            }
        }

NOTE :  for Edit mode try below code

<MasterTableView DataKeyNames="ID,Name">
               <Columns>
                   <telerik:GridBoundColumn DataField="ID" UniqueName="ID" HeaderText="ID" ReadOnly="true">
                   </telerik:GridBoundColumn>
                   <telerik:GridTemplateColumn DataField="Name" UniqueName="Name" HeaderText="Name">
                       <ItemTemplate>
                           <%# Eval("Name") %>
                       </ItemTemplate>
                       <EditItemTemplate>
                           <asp:TextBox ID="TextBox1" runat="server" Text='<%# Eval("Name") %>'></asp:TextBox>
                       </EditItemTemplate>
                   </telerik:GridTemplateColumn>
                   <telerik:GridEditCommandColumn></telerik:GridEditCommandColumn>
               </Columns>
           </MasterTableView>
protected void Button1_Click(object sender, EventArgs e)
        {
            foreach (GridEditableItem item in RadGrid1.EditItems)
            {
                string OldName = item.GetDataKeyValue("Name").ToString();
                string newName = (item.FindControl("TextBox1") as TextBox).Text.Trim();
 
                if (OldName != newName)
                {
                    // Perform DB operation here
                }
            }
        }


let me know if any concern.

Thanks,
Jayesh Goyani
0
nhaydon
Top achievements
Rank 1
answered on 26 Aug 2011, 09:06 PM
Thanks for the reply but the problem with this approach is my cells are already in edit mode when the grid loads so there is no item template
0
Jayesh Goyani
Top achievements
Rank 2
answered on 26 Aug 2011, 09:08 PM
hello,

i already add code for edit and normal case.

please search "for Edit mode" in my last post.

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