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

Get Selected Row

1 Answer 74 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Milton
Top achievements
Rank 1
Milton asked on 23 Dec 2011, 06:12 PM
Hello People.
Im trying to get id of selected row as asp.net code bellow:

                    <telerik:RadGrid ID="grdProCodes" OnPreRender="grdProCodes_PreRender" AllowMultiRowSelection="true" Visible="true" AutoGenerateColumns="false"
                        runat="server">
                        <ClientSettings EnableRowHoverStyle="true">
                            <Selecting AllowRowSelect="true" />
                        </ClientSettings>

                        <MasterTableView>
                            <Columns>
                                <telerik:GridClientSelectColumn DataTextField="Id" UniqueName="idItemSelected" HeaderStyle-Width="50"
                                    HeaderText="#">

                                </telerik:GridClientSelectColumn>
                                <telerik:GridBoundColumn DataField="CorpDiscountNumber" HeaderStyle-Width="150" HeaderText="Corp. Discount Number">
                                </telerik:GridBoundColumn>
                                <telerik:GridBoundColumn DataField="PromotionCode" HeaderStyle-Width="150" HeaderText="Promotional Code">
                                </telerik:GridBoundColumn>
                                <telerik:GridBoundColumn DataField="PromotionalTitle" HeaderText="Descrição">
                                </telerik:GridBoundColumn>
                                <telerik:GridBoundColumn DataField="StartDate" HeaderStyle-Width="150" HeaderText="Data Inicial"
                                    DataFormatString="{0:dd/MM/yyyy}">
                                </telerik:GridBoundColumn>
                                <telerik:GridBoundColumn DataField="EndDate" HeaderStyle-Width="150" HeaderText="Data Final"
                                    DataFormatString="{0:dd/MM/yyyy}">
                                </telerik:GridBoundColumn>
                                <telerik:GridBoundColumn DataField="Active" HeaderStyle-Width="100" HeaderText="Ativo">
                                </telerik:GridBoundColumn>
                            </Columns>
                        </MasterTableView>
                    </telerik:RadGrid>

When I click in button to do a Post Back in my page, my RadGrid can't detect all my checkbox is checked as the follow code bellow:

                foreach (GridDataItem itemGrid in grdProCodes.MasterTableView.Items)
                {
                    if (itemGrid.Selected)
                    {
                        int idItemSelected = Convert.ToInt32(itemGrid["idItemSelected"]);
                    }
                }

Best Regards,

Milton Camara

1 Answer, 1 is accepted

Sort by
0
Accepted
Pavlina
Telerik team
answered on 23 Dec 2011, 07:16 PM
Hello,

You can hook the SelectedIndexChanged server event of the grid to detect which item has been selected and perform additional operations if needed. Note that postback to the server is needed in order to fire SelectedIndexChanged (AutoPostBack property should be set to true).

All the best,
Pavlina
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now
Tags
Grid
Asked by
Milton
Top achievements
Rank 1
Answers by
Pavlina
Telerik team
Share this question
or