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

radgrid selected row always gives false

1 Answer 83 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Sam
Top achievements
Rank 1
Sam asked on 19 Oct 2012, 12:12 PM

<telerik:RadGrid ID="grdIn" runat="server" OnLoad="grdIn_OnLoad" OnNeedDataSource="grdIn_NeedDataSource"

                                    SkinID="CR" GridLines="None" AllowPaging="True"  AutoGenerateColumns="False" OnItemDataBound="grdIn_ItemDataBound"

                                    AllowMultiRowSelection="true" Width="925px">

                                    <MasterTableView PageSize="10"

                                        DataKeyNames="ID">

                                      

                                        <NoRecordsTemplate>

                                            <div style="text-align: left; width: 100%">

                                                <asp:Label ID="lblEmptyMsg" runat="server" meta:resourcekey="lblEmptyMsg2Resource1"></asp:Label></div>

                                        </NoRecordsTemplate>

                                    </MasterTableView>

                                    <PagerStyle AlwaysVisible="True" />

                                    <ClientSettings EnableRowHoverStyle="true">

                                        <Selecting AllowRowSelect="True" />

                                        <Scrolling AllowScroll="True"></Scrolling>

                                        <ClientEvents OnGridCreated="GridCreated" />

                                    </ClientSettings>

                                </telerik:RadGrid>



 protected void btne_Click(object sender, EventArgs e)
    {
          foreach (Telerik.Web.UI.GridItem objGrdItem in grdIn.Items)
            {    if (objGrdItem.Selected)
                {
                   int Id = (int)(objGrdItem.OwnerTableView.DataKeyValues[objGrdItem.ItemIndex]["ID"]);
                 
                 }
            }

}






1 Answer, 1 is accepted

Sort by
0
Jayesh Goyani
Top achievements
Rank 2
answered on 21 Oct 2012, 05:27 PM
Hello,

Please try with below code snippet.

protected void RadButton2_Click(object sender, EventArgs e)
        {
            foreach(GridDataItem iten in RadGrid1.MasterTableView.GetSelectedItems())
            {
                string strId = iten.GetDataKeyValue("ID").ToString();
            }
        }

if you get "RadGrid1.MasterTableView.GetSelectedItems().Length == 0" then please make sure before coming to this button click event your grid must not been rebind/reassigned Datasource.

Thanks,
Jayesh Goyani
Tags
General Discussions
Asked by
Sam
Top achievements
Rank 1
Answers by
Jayesh Goyani
Top achievements
Rank 2
Share this question
or