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

why I cant select first row. Please help.

2 Answers 29 Views
Grid
This is a migrated thread and some comments may be shown as answers.
aykut
Top achievements
Rank 1
aykut asked on 09 Oct 2013, 06:09 AM
no matter what I did, I cant select first row. What I'm missing ?
I want to first row to be selected on page load.
items.count is always 0. to find out problem I created a new page with only grid and sqldatasource. still could not found d anything.

<telerik:RadGrid ID="RadGrid1" runat="server" CellSpacing="0" DataSourceID="SqlDataSource1" GridLines="None">
    <ClientSettings>
        <Selecting AllowRowSelect="True" />
    </ClientSettings>
    <MasterTableView AutoGenerateColumns="False" DataKeyNames="ID" DataSourceID="SqlDataSource1">
        <RowIndicatorColumn Visible="False">
        </RowIndicatorColumn>
        <ExpandCollapseColumn Created="True">
        </ExpandCollapseColumn>
        <Columns>
            <telerik:GridBoundColumn DataField="ID" DataType="System.Int32" FilterControlAltText="Filter ID column" HeaderText="ID" ReadOnly="True" SortExpression="ID" UniqueName="ID">
                <ColumnValidationSettings>
                    <ModelErrorMessage Text="" />
                </ColumnValidationSettings>
            </telerik:GridBoundColumn>
    
            <telerik:GridBoundColumn DataField="urun" FilterControlAltText="Filter urun column" HeaderText="urun" SortExpression="urun" UniqueName="urun">
                <ColumnValidationSettings>
                    <ModelErrorMessage Text="" />
                </ColumnValidationSettings>
            </telerik:GridBoundColumn>
        </Columns>
    </MasterTableView>
</telerik:RadGrid>


Protected Sub Page_Load(sender As Object, e As EventArgs) Handles Me.Load
    Dim c As Integer
 
    c = RadGrid1.MasterTableView.Items.Count
 
End Sub
 
Protected Sub Page_PreRender(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.PreRender
    If (RadGrid1.MasterTableView.Items.Count > 0) Then
        If (RadGrid1.SelectedItems.Count = 0) Then
            RadGrid1.MasterTableView.Items(0).Selected = True
        End If
    End If
End Sub

2 Answers, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 1
answered on 09 Oct 2013, 06:27 AM
Hi Aykut,

I guess you want to keep the first row selected during page load.Please put the code in the OnPreRender event of the radgrid.

VB:
Protected Sub RadGrid1_PreRender(sender As Object, e As EventArgs)
    If (RadGrid1.MasterTableView.Items.Count > 0) Then
        If (RadGrid1.SelectedItems.Count = 0) Then
            RadGrid1.MasterTableView.Items(0).Selected = True
        End If
    End If
End Sub

Thanks,
Shinu
0
aykut
Top achievements
Rank 1
answered on 09 Oct 2013, 07:04 AM
pufff,silly me... I used page_prerender right... sorry and thank you very much.
Tags
Grid
Asked by
aykut
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 1
aykut
Top achievements
Rank 1
Share this question
or