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

Programmatic Retrieval of a Grid Items Value

1 Answer 104 Views
Grid
This is a migrated thread and some comments may be shown as answers.
James Legan
Top achievements
Rank 1
James Legan asked on 09 Mar 2009, 07:25 PM
Since there is not RadListbox, I have started to use RadGrid in its place.

I have a need to programmatically access the value of a particular grid item. All of the client-settings are enabled to allow for a selectedindexchanged event. There is a series of 5 grids that are programmatically built based on the selection in the previous grid.

The first grid is bound to a simple List<string>.

 

// Grid Code

 

rgDailyBuilds.DataSource = oDailyBuildFolder.DailyBuilds.ToList<

string>();

 

rgDailyBuilds.DataBind();

On the selected index change, I need to access the value of the grid item that was selected. Currently, I only allow for single select but in the future I will allow multiple select. That said, I started to approach it like this:

 

// Grid Code

 

 

 

GridItemCollection oGic = rgDailyBuilds.SelectedItems;

 

 

string sValue = string.Empty;

 

 

foreach (GridDataItem o in oGic)

 

    sValue =

Convert.ToString(o.GetDataKeyValue("Item"));

But didn't get far. How can I access the values? Also, what if the grid contained more than one column. How would I retrieve the value from a single column of a row?

Thanks,

Jim

 

1 Answer, 1 is accepted

Sort by
0
Daniel
Telerik team
answered on 10 Mar 2009, 08:56 AM
Hello James,

I already answered your support ticket. Sample code-snippet is shown below:

<telerik:RadAjaxPanel ID="RadAjaxPanel1" runat="server"
    <asp:Button ID="Button1" runat="server" Text="Get selected items"  
        onclick="Button1_Click" /> 
    <telerik:RadGrid ID="RadGrid1" runat="server" Skin="Vista" ShowHeader="false" AllowMultiRowSelection="true" 
        Width="200px"
        <ClientSettings Selecting-AllowRowSelect="true" EnablePostBackOnRowClick="true" /> 
    </telerik:RadGrid> 
</telerik:RadAjaxPanel> 

protected void Button1_Click(object sender, EventArgs e) 
    string message = ""
    foreach (GridDataItem item in RadGrid1.SelectedItems) 
        message += item["ID"].Text + "\n"
    RadAjaxPanel1.Alert(message); 

protected void Page_Load(object sender, EventArgs e) 
    DataTable table = new DataTable(); 
    table.Columns.Add("ID"typeof(int)); 
    for (int row = 0; row < 10; row++) 
        table.Rows.Add(row); 
 
    RadGrid1.DataSource = table; 

Best regards,
Daniel
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
Tags
Grid
Asked by
James Legan
Top achievements
Rank 1
Answers by
Daniel
Telerik team
Share this question
or