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"));
- }
-
11 comments:
Great job, well explained! Thanks a lot!
How to Control Hunger will cause you with a natural diet. Fast loss will be vital to losing weight healthily. Mints to Lose Hunger are a natural way to suppress hunger.
Need to have a new cell phone tracker
Hunger Suppression will assist you lose weight without a diet. Easy fat loss will be vital to losing weight healthily. Mint Appetite Suppression are key and an important way to suppress appetite.
whoah this weblog is excellent i love reading your articles.
Stay up the great work! You realize, a lot of individuals are searching around for this information, you can aid them greatly.
Take a look at my weblog ; Buy Saffron X
Hurrah! In the end I got a website from where I can truly
get helpful information concerning my study and knowledge.
Here is my web site Green Coffee Bean
Hi there! I'm at work surfing around your blog from my new iphone! Just wanted to say I love reading your blog and look forward to all your posts! Carry on the great work!
Also visit my web-site ... Coffee Bean
Hey! I could have sworn I've been to this site before but after checking through some of the post I realized it's
new to me. Anyhow, I'm definitely delighted I found it and I'll be bookmarking and checking back often!
Also see my page > Cell Phone Trackerz Website
I think the admin of this website is genuinely working hard in support of his web site,
because here every stuff is quality based data.
Also see my website: mobile hotspot
What's up, just wanted to mention, I enjoyed this post. It was inspiring. Keep on posting!
Review my weblog: Best online backup providers
Set row selection in GridView
Post a Comment