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

How to get the edit row in rad grid?

5 Answers 652 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Akki
Top achievements
Rank 1
Akki asked on 17 May 2012, 03:47 AM

Hi,
 I have used a radgrid with template coulmns which contains dropdowns and textbox..
 Now i will change these values. Button which saves these changes in radgrid is outside of radgrid. Now how can i identify only edited rows in radgrid and save ?

Below is code with only template columns
 <MasterTableView AllowFilteringByColumn="true">
                    <Columns>
                        <%--<telerik:GridBoundColumn HeaderText="Group Level" UniqueName="prdlvl" DataField="prdlvl"
                            Visible="true" ReadOnly="true">
                        </telerik:GridBoundColumn>--%>
                        <telerik:GridTemplateColumn HeaderText="Group Level" UniqueName="prdlvl" Visible="true">
                            <ItemTemplate>
                                <asp:Label ID="afslblproductlvl" runat="server" Text='<%#Eval("prdlvl")%>'></asp:Label>
                            </ItemTemplate>
                            </telerik:GridTemplateColumn>
                            <%--        <telerik:GridBoundColumn HeaderText="Description" UniqueName="prdlvldsc" DataField="prdlvldsc"
                                Visible="true">
                            </telerik:GridBoundColumn>--%>
                            <telerik:GridTemplateColumn HeaderText="Description" UniqueName="prdlvldsc" DataField="budverdsc"
                                Visible="true">
                                <itemtemplate>
                         <asp:TextBox ID = "afstxtProductGrpDescription" runat="server"  Text='<%#Eval("prdlvldsc")%>' Width= "100%"></asp:TextBox>
                             </itemtemplate>
                            </telerik:GridTemplateColumn>
                    </Columns>
                </MasterTableView>

Will looping each item can i know which item is edited in ??

foreach (GridDataItem ObjeACH in rdGrdMenu.Items)
        {
}

Regards,
Akki

5 Answers, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 17 May 2012, 05:09 AM
Hello Akki,

Try the following code snippet to achieve your scenario.
C#:
protected void Button2_Click(object sender, EventArgs e)
{
   foreach (GridDataItem item in RadGrid1.MasterTableView.Items)
   {
       TextBox txt = (TextBox)item.FindControl("afstxtProductGrpDescription");
       string value = txt.Text;
   }
}

Thanks,
Shinu.
0
Akki
Top achievements
Rank 1
answered on 17 May 2012, 06:05 AM
Thanks shinu for reply,

But without loopin each griddata item , can i get the row which is edited ??

Regards,
Kiran
0
Shinu
Top achievements
Rank 2
answered on 18 May 2012, 05:53 AM
Hi Akki,

To avoid looping try adding an OnTextChanged event handler to the TextBox cast the sender to TextBox, then use NamingContainer as a GridDataItem. Please check the following code.

ASPX:
<telerik:GridTemplateColumn HeaderText="Description" UniqueName="prdlvldsc" DataField="budverdsc" Visible="true">
  <itemtemplate>
      <asp:TextBox ID = "afstxtProductGrpDescription" runat="server"  Text='<%#Eval("prdlvldsc")%>' Width= "100%" AutoPostBack="true" ontextchanged="afstxtProductGrpDescription_TextChanged"></asp:TextBox>
  </itemtemplate>
</telerik:GridTemplateColumn>

C#:
protected void afstxtProductGrpDescription_TextChanged(object sender, EventArgs e)
{
    TextBox txtbox = (TextBox)sender;
    GridDataItem item = (GridDataItem)txtbox.NamingContainer;
    int keyValue = Convert.ToInt32(item.GetDataKeyValue("DataKeyName").ToString());  // Get the datakeyValue of that edited row
}

Thanks,
Shinu.
0
Akki
Top achievements
Rank 1
answered on 29 May 2012, 07:08 AM
Thanks shinu,
 It worked .. but i want to update only the edited row to database. how can i get the rows which are edited.
With loop i will get the all the rows in grid .. is there any property which says IsRowEdited ?? something like this?
Please let me know.

Regards,
Akki
0
Shinu
Top achievements
Rank 2
answered on 29 May 2012, 10:37 AM
Hi Akki,

Try the following code snippet to update only the edited row to database by looping only through edited rows.
 
C#:
public static ArrayList IndexArray = new ArrayList();
protected void afstxtProductGrpDescription_TextChanged(object sender, EventArgs e)
{
    TextBox txtbox = (TextBox)sender;
    GridDataItem item = (GridDataItem)txtbox.NamingContainer;
    index= item.ItemIndex;
    IndexArray.Add(index);
}
protected void Button2_Click(object sender, EventArgs e)
{
    foreach (int i in IndexArray)
    {
       GridDataItem item = (GridDataItem)RadGrid1.MasterTableView.Items[i];
       TextBox txt = (TextBox)item.FindControl("afstxtProductGrpDescription");
       string value = txt.Text;
       // code to update
    }
}

Thanks,
Shinu.
Tags
Grid
Asked by
Akki
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
Akki
Top achievements
Rank 1
Share this question
or