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

get row based on datakey value and remove

1 Answer 850 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Prathibarani
Top achievements
Rank 1
Prathibarani asked on 17 Jul 2013, 08:55 PM
Hi,
  
I have datakeyname value. I need to get a row using this key value out of Radgrid events. All the code
is in Radgrid events. Out of Radgrid events means, they suggest to loop thru
Rows and get a row like this:
  
Foreach (GridDataItem row in Radgrid1.Items)
{
    If (row.GetDataKeyValue(“ID”).ToString() == “100”)
               Row.Remove;
}
  
One more thing is that when that particular row is found, I need to delete it from grid.
But GridDatItem (row) doesn’t have delete or remove method. It has only dispose. I don’t think dispose
does the job of delete. I don’t want grid to be rebound after deleting row.
  
Please suggest how to do it. We are not using needsource event to bind grid. Our architecture will not
suit to use it. So, we bind the grid where ever necessary. I need to have this code for our page to work.
  
Thanks,
Prathiba.

1 Answer, 1 is accepted

Sort by
0
Jayesh Goyani
Top achievements
Rank 2
answered on 18 Jul 2013, 05:26 AM
Hello,

Please try with the below code snippet.

<telerik:RadGrid ID="RadGrid1" runat="server" AutoGenerateColumns="false">
       <MasterTableView DataKeyNames="ID">
           <Columns>
               <telerik:GridBoundColumn DataField="ID" UniqueName="ID" HeaderText="ID">
               </telerik:GridBoundColumn>
           </Columns>
       </MasterTableView>
   </telerik:RadGrid>
   <asp:Button ID="Button1" runat="server" Text="Button" onclick="Button1_Click" />
protected void Page_Load(object sender, System.EventArgs e)
   {
 
       dynamic data = new[] {
           new { ID = 1, Name = "Name1"},
           new { ID = 2, Name = "Name2"},
           new { ID = 3, Name = "Name3"},
           new { ID = 4, Name = "Name4"},
           new { ID = 5, Name = "Name5"}
       };
 
       RadGrid1.DataSource = data;
       RadGrid1.DataBind();
   }
 
protected void Button1_Click(object sender, EventArgs e)
   {
       foreach (GridDataItem item in RadGrid1.MasterTableView.Items)
       {
           if (item.GetDataKeyValue("ID").ToString() == "3")
           {
               item.Visible = false;
           }
       }
   }


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