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

Grid, Paging and ItemCommand

6 Answers 197 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Anatoly
Top achievements
Rank 1
Anatoly asked on 02 Sep 2008, 03:42 PM
Hi.
I use RadGrid with paging. All columns in grid are GridButtonColumn. When I handle ItemCommand event  e.Item.DataItem == null but  e.Item.IsDataBound == true. How can I get my databound object?

6 Answers, 1 is accepted

Sort by
0
Veli
Telerik team
answered on 02 Sep 2008, 06:15 PM
Hello Anatoliy,

The safest way to retrieve the data object from the source is by looking directly into the source table or view. Generally, you can convert your e.Item to a GridDataItem and take a unique cell value from it that you can use for querying your database. This way, you can ensure that the retrieved data source item is represented by your GridDataItem.

Greetings,
Veli
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
0
Anatoly
Top achievements
Rank 1
answered on 03 Sep 2008, 04:29 PM

Hi.
I do this:
protected
void grid_ItemCommand(object source, GridCommandEventArgs e)

{

GridDataItem Item = e.Item as GridDataItem;

foreach (TableCell item in Item.Cells)

{

string str = item.Text;

}

str == " " for all cells
0
Missing User
answered on 03 Sep 2008, 04:36 PM
Hello Anatoliy,


To see more information on the requested functionality, please refer to the following article - Accessing cells and rows. I hope this information helps.

Kind regards,
Plamen
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
0
Anatoly
Top achievements
Rank 1
answered on 03 Sep 2008, 04:52 PM

I do this:
protected
void grid_ItemCommand(object source, GridCommandEventArgs e)

{

GridDataItem Item = e.Item as GridDataItem;

string s = Item["ServiceName"].Text;

but s again is " "

maybe it happens because I bind my grid via NeedDataSource event

0
Vlad
Telerik team
answered on 04 Sep 2008, 05:40 AM
Hi Anatoliy,

Most probably you have a control in this cell. When a TableCell Controls collection is not empty the cell Text will be empty.

Greetings,
Vlad
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
0
Shinu
Top achievements
Rank 2
answered on 04 Sep 2008, 06:05 AM
Hi Anatoliy,

Try accessing the text of a GridButtonColumn as shown below.


ASPX:
 <telerik:GridButtonColumn DataTextField="ProductName" ButtonType="linkButton" UniqueName="BtnCol"></telerik:GridButtonColumn> 
                

CS:
 protected void RadGrid1_ItemCommand(object source, GridCommandEventArgs e) 
    { 
        GridDataItem item = (GridDataItem)e.Item; 
        LinkButton lnkbtn = (LinkButton)item["BtnCol"].Controls[0]; 
        string strtxt = lnkbtn.Text; 
    } 
 

Thanks
Shinu.
Tags
Grid
Asked by
Anatoly
Top achievements
Rank 1
Answers by
Veli
Telerik team
Anatoly
Top achievements
Rank 1
Missing User
Vlad
Telerik team
Shinu
Top achievements
Rank 2
Share this question
or