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

[Solved] Extracting cell values from RADGrid

4 Answers 507 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Ken
Top achievements
Rank 1
Ken asked on 23 Jun 2009, 08:49 PM
I admit I am new to this component set, but here's what I am running into. I am using Visual Studio 2008.

I have my dataset and my grid, no problem there. I have selection allowed on the grid, and that works correctly. After some research here, I have the following code:

<script type="text/javascript">
 function RowSelected(sender, eventArgs)
 {
   var label = window.document.getElementById("TextBox1");
   var dataItem = $get(eventArgs.get_id());
   var grid = sender;
   var MasterTable = grid.get_masterTableView();
   var row = MasterTable.get_dataItems()[eventArgs.get_itemIndexHierarchical()];
   var cell = MasterTable.getCellByColumnUniqueName(row, "transaction_number");
   label.Value = cell.innerHTML;
   alert("Cell Value: " + label.Value);

  //here cell.innerHTML holds the value of the cell
 }

</script>

This brings up the transaction number in an alert box. But how in the world do I get this and other cell values back to where the VB.Net code can use them?

All help appreciated. I am well and thoroughly stuck.





4 Answers, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 24 Jun 2009, 04:25 AM
Hi Ken,

You can access the selecteditem values of radgrid in SelectionIndexChanged event as shown below.

VB:
 
Protected Sub RadGrid1_SelectedIndexChanged(ByVal sender As ObjectByVal e As EventArgs) 
    For Each item As GridDataItem In RadGrid1.SelectedItems 
        Dim value As [String] = item("transaction_number").Text.ToString() 
        Response.Write(value) 
        ' First selected item 
        'string value1 = (RadGrid1.SelectedItems[0] as GridDataItem)["transaction_number"].Text.ToString(); 
        'Response.Write(value1); 
    Next 
End Sub 
Note: Set the ClientSettings-EnablePostBackOnRowClick property to True in order to fire SelectionIndexChanged on selecting the row.

Thanks,
Shinu.
0
Ken
Top achievements
Rank 1
answered on 24 Jun 2009, 01:31 PM
This still does nothing. Here's what I have now:

        <telerik:RadGrid ID="RadGrid1" runat="server" DataSourceID="SqlDataSource3"
            GridLines="None" Skin="Vista"
            AutoGenerateColumns="False" Width="582px"  
            onitemdatabound="RadGrid1_ItemDataBound"
            onselectionindexchanged="RadGrid1_SelectionIndexChanged"
            Height="298px"
            ShowStatusBar="True" >

    Protected Sub RadGrid1_SelectionIndexChanged(ByVal sender As Object, ByVal e As EventArgs)
        'For Each item As GridDataItem In RadGrid1.SelectedItems
        'Dim value As [String] = item("transaction_number").Text.ToString()
        'TextBox1.Text = item("transaction_number").Text.ToString()
        ' First selected item
        'string value1 = (RadGrid1.SelectedItems[0] as GridDataItem)["transaction_number"].Text.ToString();
        'Response.Write(value1);
        TextBox1.Text = "Hello"
        'Next
    End Sub

I commented out everything but the assignment to TextBox1, and still nothing. I get no error message, but nothing changed when I click on a grid row. It acts as though the event is never being fired.

 I am using the Q12008 version of these controls, but I don't know if that is the problem.







0
Ken
Top achievements
Rank 1
answered on 24 Jun 2009, 01:33 PM
Forgot to post the rest of the grid settings:

            <HeaderStyle Font-Bold="True" />
            <ClientSettings EnablePostBackOnRowClick="True">
                <Selecting AllowRowSelect="True"/>

                <Scrolling AllowScroll="True" UseStaticHeaders="True" />
            </ClientSettings>
        </telerik:RadGrid>
0
Daniel
Telerik team
answered on 26 Jun 2009, 02:13 PM
Hello Ken,

For your convenience I attached a simple demo to this post. Please test it locally and let me know if you have any questions.

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
Ken
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
Ken
Top achievements
Rank 1
Daniel
Telerik team
Share this question
or