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

Problem in Accessing Grid Rows from ItemCommand

4 Answers 123 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Clement
Top achievements
Rank 2
Clement asked on 17 Jun 2008, 02:23 AM
Dear Friends,

I'm trying to access the Grid Rows inside the RadGrid1_ItemCommand() :

protected void grdSFOOrders_ItemCommand(object source, Telerik.Web.UI.GridCommandEventArgs e)
    {

        //// The Following segment is written for handling the Custom Command Item for Converting SO Items in the Grid to SFO
        if (e.CommandName == "CreateSFO")
        {
            // CreateSFO Command Item Pressed

            //Traverse thru the Rows in the SFOOrders Basket Grid and Create an SFO

            //e is the event argument object

IS THIS THE RIGHT WAY SINCE THE CONTROL IS NOT FLOWING THRU THIS IF LOOP ???

            if (e.Item is GridDataItem)
            {
                GridDataItem dataItem = e.Item as GridDataItem;

                string sono = dataItem["SONo"].Text;

                string sodetailid = dataItem["SODetailID"].Text;

                string custname = dataItem["CustName"].Text;

                string sodate = dataItem["SODate"].Text;

                string itemcode = dataItem["ItemCode"].Text;

                string qty = dataItem["Qty"].Text;

                string addtlinfo = dataItem["AddtlInfo"].Text;

               
            }

            else if (e.Item is GridEditFormItem)
            {
                GridEditFormItem editItem = e.Item as GridEditFormItem;
            }

        }

    }

I'M NOT ABLE TO ACCESS THE ROWS TO GET THE VALUES. PLS HELP !

Thanks
Clement

4 Answers, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 17 Jun 2008, 04:25 AM
Hi Clement,

Try accessing the Grid Rows in the ItemDataBound event as shown below.

CS:
 protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e)  
    {  
        if (e.Item is GridDataItem)  
        {  
            GridDataItem item = (GridDataItem)e.Item;  
            string strtxt = item["columnUniqueName"].Text.ToString();  
        }  
         
    } 

Thanks
Princy.
0
Clement
Top achievements
Rank 2
answered on 17 Jun 2008, 05:37 AM
Princy,

Thanks for the Snippet, BUT I need to get the Row Values when user clicks on the Command - CreateSFO in the CommandItemTemplate.

I'm using the Example for Drag and Drop (http://www.telerik.com/DEMOS/ASPNET/Prometheus/Grid/Examples/Programming/DragAndDrop/DefaultCS.aspx)

MY OBJECTIVE : I have added a Command on the Shipped Orders Grid, When users click this command after dragging and droping the Rows from Pending Orders grid, I need to collect the values in all the Rows of ShippedOrders and insert them into the DB.

Hope u understand my query ! Pls Help

Thanks for your time
Clement
0
Accepted
Shinu
Top achievements
Rank 2
answered on 17 Jun 2008, 06:22 AM
Hi Clement,

Try the following code snippet to access the row in the ItemCommand event.

CS:
 protected void RadGrid1_ItemCommand(object source, GridCommandEventArgs e) 
    { 
       if (e.CommandName == "CreateSFO") 
        { 
            foreach (GridDataItem item in RadGrid1.MasterTableView.Items) 
            { 
                string strTxt = item["CustomerID"].Text.ToString(); 
            } 
        } 
         
    } 
 

Thanks
Shinu.
0
Clement
Top achievements
Rank 2
answered on 17 Jun 2008, 06:39 AM
Hi Princy & Shinu,

Thanks for your Tips and Snippets.

Its working now and i had tried it with :

foreach (GridDataItem item in grdSFOOrders.Items){}

Thanks A Lot
Clement
Tags
Grid
Asked by
Clement
Top achievements
Rank 2
Answers by
Princy
Top achievements
Rank 2
Clement
Top achievements
Rank 2
Shinu
Top achievements
Rank 2
Share this question
or