I found that with the flood of new possibilities with DevExpress grid view a simple functionality of selecting one row is bit hidden. After doing bit of searching in the internet I found the way and thought to share it.
The way we need to do this is by using a java script and bind that in to the RowClick event of the grid.
The java script will look like the following.
<script type="text/javascript">
function OnRowClick(e) {
//Unselect all rows
dxgdSearch._selectAllRowsOnPage(false);
//Select the row
dxgdSearch.SelectRow(e.visibleIndex, true);
}
</script>
Then the binding to the RowClick would be as below.
<ClientSideEvents RowClick="function(s, e) { OnRowClick(e); }"></ClientSideEvents>
The outcome of this is a grid which you can select a row.
The value of the selected row can be taken as below.
dxgdSearch.GetRowValues(dxgdSearch.FocusedRowIndex, "Customer_ID")
For example in my application I used to pass the Customer Id to the Customer.aspx form as below.
- Response.Redirect("~/Customer.aspx?cusID= " + dxgdSearch.GetRowValues(dxgdSearch.FocusedRowIndex, "Customer_ID"));
-
The full source is as of below.
Page.aspx
- <asp:Content ID="Content4" ContentPlaceHolderID="MainContent" runat="server">
- <script type="text/javascript">
- function OnRowClick(e) {
- //Unselect all rows
- dxgdSearch._selectAllRowsOnPage(false);
- //Select the row
- dxgdSearch.SelectRow(e.visibleIndex, true);
- }
- </script>
- <dx:ASPxGridView ID="dxgdSearch" ClientInstanceName="dxgdSearch" runat="server" AutoGenerateColumns="False"
- SettingsBehavior-AllowFocusedRow="True" SettingsBehavior-AllowMultiSelection="False">
- <ClientSideEvents RowClick="function(s, e) { OnRowClick(e); }"></ClientSideEvents>
- <Columns>
- <dx:GridViewDataTextColumn Name="Id" ShowInCustomizationForm="True" VisibleIndex="1"
- Caption="Customer ID" FieldName="Customer_ID" Visible="False">
- </dx:GridViewDataTextColumn>
- <dx:GridViewDataTextColumn Name="Name" ShowInCustomizationForm="True" VisibleIndex="0"
- Caption="Name" FieldName="Full_Name">
- </dx:GridViewDataTextColumn>
- <dx:GridViewDataTextColumn Name="TelephoneNo" ShowInCustomizationForm="True" VisibleIndex="1"
- Caption="Tele. No." FieldName="Mobile_Number">
- </dx:GridViewDataTextColumn>
- <dx:GridViewDataTextColumn Name="EMail" ShowInCustomizationForm="True" VisibleIndex="2"
- Caption="EMail" FieldName="Email">
- </dx:GridViewDataTextColumn>
- <dx:GridViewDataHyperLinkColumn Name="Select" VisibleIndex="3">
- <DataItemTemplate>
- <asp:Button ID="Button1" runat="server" CommandArgument='<%# Eval("Customer_ID") %>'
- OnClick="Button1_Click" Text="Edit" />
- </DataItemTemplate>
- </dx:GridViewDataHyperLinkColumn>
- </Columns>
- <SettingsBehavior AllowFocusedRow="True"></SettingsBehavior>
- <Settings ShowGroupPanel="True" ShowFilterRow="True" />
- <Settings ShowFilterRow="True" ShowGroupPanel="True"></Settings>
- </dx:ASPxGridView>
- </asp:Content>
-
Page.aspx.cs
- protected void Button1_Click(object sender, EventArgs e)
- {
- Response.Redirect("~/Customer.aspx?cusID= " + dxgdSearch.GetRowValues(dxgdSearch.FocusedRowIndex, "Customer_ID"));
- }
-