
diggityDawg
Top achievements
Rank 1
diggityDawg
asked on 05 May 2008, 05:22 PM
I've been working on this for a couple days now and I'm stumped. I have a RadGrid on my page and I've set the OnSelectedIndexChanged event to a method that I've created. But when I select a row it just refreshes the page. If I run in debug mode it doesn't execute the method I've defined. If I look at the SelectedValue it's null, the SelectedIndexes.Count = 0, the SelectedItems.Count = 0. What am I missing here? This is fairly trivial to do with GridView, so I'm shocked it's causing me such a headache in RadGrid... I'd really like to be able to just select a row, not a Select checkbox or button or link. What I want to do is redirect to a detail page, based on the SelectedValue.
One more related item - is there a way to highlight rows onmouseover? Again, this is fairly simple to implement in GridView by adding an attribute in the RowDataBound method. But I've tried the same thing in RadGrid and nothing I try works. I know there's a "EnableRowHoverStyle" option, but it was left out of the build that I have for some reason, so I need a workaround.
Thanks for the help!
Eddie
One more related item - is there a way to highlight rows onmouseover? Again, this is fairly simple to implement in GridView by adding an attribute in the RowDataBound method. But I've tried the same thing in RadGrid and nothing I try works. I know there's a "EnableRowHoverStyle" option, but it was left out of the build that I have for some reason, so I need a workaround.
Thanks for the help!
Eddie
10 Answers, 1 is accepted
0

Richard
Top achievements
Rank 1
answered on 05 May 2008, 08:17 PM
Hi Eddie,
For the selected row postback, all you should need to do is add a block like the following to your grid:
<ClientSettings EnablePostBackOnRowClick="true">
<Selecting AllowRowSelect="true" />
</ClientSettings>
For the selected row postback, all you should need to do is add a block like the following to your grid:
<ClientSettings EnablePostBackOnRowClick="true">
<Selecting AllowRowSelect="true" />
</ClientSettings>
0

diggityDawg
Top achievements
Rank 1
answered on 05 May 2008, 08:38 PM
Thanks for that info. Unfortunately I still get the same thing when I use put that code into my radGrid. There is no SelectedItems in the RadGrid. It does enter the OnSelectedIndexChanged method, but when I try to do something based on the value selected I get a Null exception. Here's some of the aspx code I'm using:
Here are the methods I'm calling:
The result of this code is that I have no reference to the SelectedValue when I click on a row, and the background color of the rows don't change on mouseover. Can you see what I might be missing?
Thanks again for the help!
Eddie
<radG:RadGrid ID="RadGrid1" runat="server" AllowSorting="true" OnSelectedIndexChanged="RadGrid1_SelectedIndexChanged" OnItemDataBound="RadGrid_RowDataBound"> |
<ClientSettings EnablePostBackOnRowClick="true"> |
<Selecting AllowRowSelect="true" /> |
</ClientSettings> |
<MasterTableView DataKeyNames="Id"> |
<Columns> |
<radG:GridClientSelectColumn ButtonType="LinkButton" Text="select"></radG:GridClientSelectColumn> |
<radG:GridTemplateColumn HeaderText="NAME" HeaderStyle-Width="180px"> |
<ItemTemplate> |
<%# Eval("LastName") + ", " + Eval("FirstName") + " " + Eval("MiddleName") %> |
</ItemTemplate> |
</radG:GridTemplateColumn> |
<radG:GridTemplateColumn HeaderText="ADDRESS" HeaderStyle-Width="160px"> |
<ItemTemplate> |
<asp:Label runat="server" ID="lblAddress"></asp:Label> |
</ItemTemplate> |
</radG:GridTemplateColumn> |
<radG:GridBoundColumn HeaderText="DOB" DataField="Dob" DataFormatString="{0:d}"></radG:GridBoundColumn> |
<radG:GridBoundColumn HeaderText="ID" DataField="Id"></radG:GridBoundColumn> |
</Columns> |
</MasterTableView> |
</radG:RadGrid> |
Here are the methods I'm calling:
protected void RadGrid1_SelectedIndexChanged(object sender, EventArgs e) |
{ |
string id = RadGrid1.SelectedValue.ToString(); |
Person p = Person.getPerson(id); |
if (p != null) |
{ |
Session["CurrentPerson"] = p; |
Response.Redirect("~/Person.aspx"); |
} |
} |
protected void RadGrid_RowDataBound(object sender, GridItemEventArgs e) |
{ |
Person p = (Person) e.Item.DataItem; |
if(e.Item.ItemType == GridItemType.Item || e.Item.ItemType == GridItemType.AlternatingItem) |
{ |
e.Item.Attributes.Add("onclick", ClientScript.GetPostBackClientHyperlink(RadGrid1, "Select$" + e.Item.ItemIndex)); |
e.Item.Attributes.Add("onmouseover", "this.style.background='#efefef'"); |
} |
} |
The result of this code is that I have no reference to the SelectedValue when I click on a row, and the background color of the rows don't change on mouseover. Can you see what I might be missing?
Thanks again for the help!
Eddie
0

Richard
Top achievements
Rank 1
answered on 05 May 2008, 09:09 PM
The only thing I can see different from what I am doing is that my id column is always my first databound column. Maybe this affects the SelectedValue?
When you are in your SelectedIndexChanged method, does the SelectedItems property of your grid contain any values? Another way of getting the selected row id is:
string id = RadGrid1.MasterTableView.DataKeyValues[RadGrid1.SelectedItems[0].ItemIndex]["Id"].ToString();
The mouseover stuff isn't anything I've played with, so I don't have any suggestions there.
When you are in your SelectedIndexChanged method, does the SelectedItems property of your grid contain any values? Another way of getting the selected row id is:
string id = RadGrid1.MasterTableView.DataKeyValues[RadGrid1.SelectedItems[0].ItemIndex]["Id"].ToString();
The mouseover stuff isn't anything I've played with, so I don't have any suggestions there.
0

diggityDawg
Top achievements
Rank 1
answered on 05 May 2008, 09:47 PM
Hi Richard,
No, the SelectedItems property of my grid contains 0 items when I am in the SelectedIndexChanged method. I think that's the problem, but I'm not sure where I've gone wrong. If I check the RadGrid1.MasterTableView.DataKeyValues I have 86, which is the correct number of rows, and I can access them by index number. But I have no way of knowing what the index of the selected row is.
As for the id, I actually use a different name for the column and DateKeyName, I just put "id" into the sample code I posted. In actuality there is no "id" column in my code, so I don't think that's the issue.
Basically, I have everything working for the "Selecting" part, but I just can't get a reference to the selected row. If I can figure that out I'm nearly there...
Thanks again - eddie
No, the SelectedItems property of my grid contains 0 items when I am in the SelectedIndexChanged method. I think that's the problem, but I'm not sure where I've gone wrong. If I check the RadGrid1.MasterTableView.DataKeyValues I have 86, which is the correct number of rows, and I can access them by index number. But I have no way of knowing what the index of the selected row is.
As for the id, I actually use a different name for the column and DateKeyName, I just put "id" into the sample code I posted. In actuality there is no "id" column in my code, so I don't think that's the issue.
Basically, I have everything working for the "Selecting" part, but I just can't get a reference to the selected row. If I can figure that out I'm nearly there...
Thanks again - eddie
0

diggityDawg
Top achievements
Rank 1
answered on 06 May 2008, 03:13 PM
Well, I've been working on this for a couple days now and I'm kind of stumped at this point. Not sure what else to do. Any chance someone from Telerik can help me out?
Thanks!
Eddie
Thanks!
Eddie
0

Bodevain Svensson
Top achievements
Rank 1
answered on 06 May 2008, 04:02 PM
I think that the GridClientSelectColumn can only be of type checkbox while you are attempting to use it as link button column. Try replacing that column with GridButtonColumn which has ButtonType = LinkButton and CommandName=Select/Text=Select.
Hope this will put you on the right track. Also check whether you use NeedDataSource binding for the grid:
http://www.telerik.com/DEMOS/ASPNET/Prometheus/Grid/Examples/Programming/NeedDataSource/DefaultCS.aspx
Bodevain
Hope this will put you on the right track. Also check whether you use NeedDataSource binding for the grid:
http://www.telerik.com/DEMOS/ASPNET/Prometheus/Grid/Examples/Programming/NeedDataSource/DefaultCS.aspx
Bodevain
0

diggityDawg
Top achievements
Rank 1
answered on 06 May 2008, 07:02 PM
Thanks for the suggestions. I tried changing the ButtonType to LinkButton, and even PushButton, but none of that made any difference. I did change the CommandName and Text properties, but again, no dice. I do have a NeedDataSource method defined for the Grid, so that's not the issue either...
No matter what I do I can't get access to the SelectedItems in the Grid when I'm in the SelectedIndexChanged method... I tried casting the sender as GridItem, but that didn't work either.
Please Telerik, can you help me with this??
No matter what I do I can't get access to the SelectedItems in the Grid when I'm in the SelectedIndexChanged method... I tried casting the sender as GridItem, but that didn't work either.
Please Telerik, can you help me with this??
0

diggityDawg
Top achievements
Rank 1
answered on 06 May 2008, 09:12 PM
Ok, I found the fix for this - I needed to use ItemCommand, not SelectedIndexChanged for the RowClick. Once I did that everything worked like a charm. Now if I could just figure out how to get the rows to highlight on mouseover...
0

Tim
Top achievements
Rank 1
answered on 06 May 2008, 09:50 PM
You could try a function with code like this
<
SelectedItemStyle BackColor="#D2E9FF" />
I am not sure if this will work but it may be a good place to start0
Hello,
The RadGrid for ASP.NET AJAX official Q1 2008 version provides the highlighting rows on mouse over built-in. You just need to set the ClientSettings -> EnableRowHoverStyle to true:
You can also take a look at the following resource:
Styling Grid rows on mouse over
Regards,
Konstantin Petkov
the Telerik team
Instantly find answers to your questions at the new Telerik Support Center
The RadGrid for ASP.NET AJAX official Q1 2008 version provides the highlighting rows on mouse over built-in. You just need to set the ClientSettings -> EnableRowHoverStyle to true:
You can also take a look at the following resource:
Styling Grid rows on mouse over
Regards,
Konstantin Petkov
the Telerik team
Instantly find answers to your questions at the new Telerik Support Center