Hi guys,
I need to sort my RadGrid by the selected value in the DropDown list. The problem (not counting the fact that i am an absolute newbie in the asp.net/c#/Telerik world and the whole code is the legacy redirected to me from someone who worked on it before me) is that the values which fill the dropdown are not selected from the DataBase, they are dynamically generated in the codebehind... Oh, well, what am I talking about... here is the part of the code with the DropDownList:
and in the codebehind, here is how it is generated:
any ideas how to do it? Google search and specific search through Telerik forums didn't help me...
I need to sort my RadGrid by the selected value in the DropDown list. The problem (not counting the fact that i am an absolute newbie in the asp.net/c#/Telerik world and the whole code is the legacy redirected to me from someone who worked on it before me) is that the values which fill the dropdown are not selected from the DataBase, they are dynamically generated in the codebehind... Oh, well, what am I talking about... here is the part of the code with the DropDownList:
<telerik:RadGrid ID="RadGrid1" runat="server" Width="100%" AllowSorting="true" AllowMultiRowSelection="True" |
AllowPaging="true" PageSize="5" Skin="Telerik" OnItemDataBound="RadGrid1_ItemDataBound" |
OnNeedDataSource="RadGrid1_NeedDataSource" |
OnItemCreated="RadGrid1_ItemCreated" onitemcommand="RadGrid1_ItemCommand"> |
<MasterTableView AutoGenerateColumns="False" CommandItemDisplay="Bottom" AllowSorting="true"> |
<telerik:GridTemplateColumn HeaderText="Role" UniqueName="Role"> |
<ItemTemplate> |
<asp:DropDownList ID="ddl_Roles" CssClass="roles_list" runat="server"> |
<asp:ListItem Text="User" Value="User"></asp:ListItem> |
<asp:ListItem Text="Observer" Value="Observer" Enabled="false"></asp:ListItem> |
<asp:ListItem Text="Editor" Value="Editor" Enabled="false"></asp:ListItem> |
<asp:ListItem Text="Manager" Value="Manager" Enabled="false"></asp:ListItem> |
<asp:ListItem Text="Admin" Value="Admin"></asp:ListItem> |
</asp:DropDownList> |
<div class="button"> |
<asp:Button ID="ChangeRoleButton" CssClass="roles_change" runat="server" OnClientClick="return confirm('Are you sure you want to change this users role?');" CommandName="SaveRole" CommandArgument='<%# DataBinder.Eval(Container.DataItem, "ID") %>' Text="Save Role" /> |
</div> |
</ItemTemplate> |
</telerik:GridTemplateColumn> |
and in the codebehind, here is how it is generated:
protected void RadGrid1_ItemDataBound(object sender, Telerik.Web.UI.GridItemEventArgs e) |
{ |
if (e.Item is GridDataItem) |
{ |
GridDataItem item = (GridDataItem)e.Item; |
//Access the GridDataItem using the ColumnUniqueName |
string UserName = item["UserName"].Text; |
string businessShortName = item["SBN"].Text; |
DropDownList roleListing = (DropDownList)item["Role"].Controls[1]; |
if (Roles.IsUserInRole(UserName, businessShortName + "_admin")) |
{ |
item["UserName"].Text = roleListing.SelectedValue = "Admin"; |
} |
else if (Roles.IsUserInRole(UserName, businessShortName + "_manager")) |
{ |
item["UserName"].Text = roleListing.SelectedValue = "Manager"; |
} |
else if (Roles.IsUserInRole(UserName, businessShortName + "_editor")) |
{ |
item["UserName"].Text = roleListing.SelectedValue = "Editor"; |
} |
else if (Roles.IsUserInRole(UserName, businessShortName + "_observer")) |
{ |
item["UserName"].Text = roleListing.SelectedValue = "Observer"; |
} |
else |
{ |
item["UserName"].Text = roleListing.SelectedValue = "User"; |
} |
} |
any ideas how to do it? Google search and specific search through Telerik forums didn't help me...