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

[Solved] Selecting text values in a grid row

3 Answers 250 Views
Grid
This is a migrated thread and some comments may be shown as answers.
JohnW
Top achievements
Rank 1
JohnW asked on 21 Apr 2009, 02:00 PM
I have searched and searched and all available solutions are not working for me.

I have a RadGrid that I am databinding at runtime. Each time I select a row, it will fire the SelectedIndexChanged, but I get an index error or the value selected is nothing. I'm at my wits end here and I'm not sure how to proceed.

Here's my aspx page:

                <asp:Panel runat="server" ID="DrugList" Height="370px" Width="550" ScrollBars="Auto"
 
<telerik:RadGrid ID="rgDrugList" runat="server" AllowMultiRowSelection="True" 
                    AllowPaging="True" AllowSorting="True" AutoGenerateColumns="False" GridLines="None" 
                    Height="350px" OnItemCommand="rgDrugList_ItemCommand" 
                    Skin="Vista" Width="545px" OnselectedIndexChanged="rgDrugList_SelectedIndexChanged"
                    <MasterTableView> 
                        <PagerStyle Mode="NextPrevAndNumeric" /> 
                        <Columns> 
                            <telerik:GridBoundColumn DataField="Name" HeaderText="Drug Name" SortExpression="Name" UniqueName="Name"
                            </telerik:GridBoundColumn> 
                        </Columns> 
                    </MasterTableView> 
                    <ClientSettings EnablePostBackOnRowClick="true"
                        <Selecting AllowRowSelect="True" /> 
                    </ClientSettings> 
                </telerik:RadGrid> 
                 
                </asp:Panel> 

And here's my vb code:

    Protected Sub form1_Load(ByVal sender As ObjectByVal e As System.EventArgs) Handles form1.Load 
        InitializeData() 
    End Sub 
 
    Protected Sub InitializeData() 
        Dim o As New localhost.Service1 
        Dim ds As New DataSet 
 
        ds = o.GetNumbderDrugData 
 
        If ds Is Nothing Then 
            errorPanel.Visible = True 
            Exit Sub 
        End If 
 
        If ds.Tables(0).Rows.Count = 0 Then 
            errorPanel.Visible = True 
            Exit Sub 
        Else 
            errorPanel.Visible = False 
            rgDrugList.DataSource = ds 
            rgDrugList.DataBind() 
          
        End If 
    End Sub     
 
 
Protected Sub rgDrugList_SelectedIndexChanged(ByVal sender As ObjectByVal e As System.EventArgs) Handles rgDrugList.SelectedIndexChanged 
        Dim item As GridDataItem = DirectCast(rgDrugList.SelectedItems(0), GridDataItem) 
        ' Get the first selected item 
        If True Then 
            MsgBox(item("Name").Text) 
        End If 
    End Sub 

I have tried using a button as well to fire the event. This doesn't seem to be the issue, as the event fires, I just can't get the value selected. Any help here would be greatly appreciated.





3 Answers, 1 is accepted

Sort by
0
Accepted
Daniel
Telerik team
answered on 21 Apr 2009, 03:08 PM
Hello John,

For your convenience I created simple demo project illustrating how to achieve the desired functionality. Please test it on your end and let us know if you need further assistance.

Kind 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.
0
JohnW
Top achievements
Rank 1
answered on 21 Apr 2009, 03:28 PM
Daniel, thank you so much... I'm not sure what I was doing wrong, because even when I used the OnSelectedIndexChanged I still would not get a value.

OK, next minor issue, the SelectedIndexChanged event is firing twice, any quick fix for that?
0
Accepted
Daniel
Telerik team
answered on 24 Apr 2009, 05:05 PM
Hello John,

Please remove one of the following:
Handles rgDrugList.SelectedIndexChanged 

or:
OnSelectedIndexChanged="rgDrugList_SelectedIndexChanged" 

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