Telerik RadGrid: Processing Selected Items in a Grid

I don't know what your problem is, but I'll bet it's hard to pronounce.

Telerik RadGrid: Processing Selected Items in a Grid

Postby ShiftPoint » Sun Jul 05, 2009 9:10 pm

After working on this for the past few days I was finally able to get it working. Let me give a little background first. First off I have a radgrid (RadGrid1) that is created on the fly when the page loads (Page_Init). I needed to cycle through each item in the grid and obtain certain peices of information from a few of the fields when the user clicks on a given button (Button1).

Essentailly the user would be presented a grid via an aspx page that contains some information. The user can select rows from the grid that they want to process. Once the user makes their selection and clicks Button1 the Button1_Click() method is invoked and processes only the selected records. Each row will be processed and the code will call a stored procedure to insert records into a MS SQL table.

Keep in mind this assumes you have already created a radgrid called "RadGrid1" and binded all of the data correctly. It also assumes you have placed the grid to a placeholder called "PlaceHolder1". Here is an example of the Button1_Click() method:

Code: Select all
     protected void Button1_Click(object sender, System.EventArgs e )

     {

                 RadGrid radGrid1 = null;

         for (int i = 0; i < this.PlaceHolder1.Controls.Count; i++)

         {

             if (this.PlaceHolder1.Controls[i].GetType() == typeof(RadGrid))

             {

                 radGrid1 = (RadGrid)this.PlaceHolder1.Controls[i];

                break;

            }

         }



        if (radGrid1 != null)

        {

             GridDataItem row = null;

           string pkey;



            for (int i = 0; i < radGrid1.SelectedItems.Count; i++)

             {

               row = (GridDataItem)radGrid1.SelectedItems[i];

                pkey = radGrid1.SelectedItems[i].Cells[0].Text;



                //Call method that inserts records into MS SQL here//

             }


         }

     }

User avatar
ShiftPoint
 
Posts: 70
Joined: Sun Jul 05, 2009 4:52 pm
Location: Pickerington, OH

Return to ASP.Net

Who is online

Users browsing this forum: No registered users and 0 guests

cron