hello,
on my ASPX page I have two controls: a DropDownList, and a RadGrid. when the DropDownList posts back, I want to update the data in the RadGrid based on the list's current selected value.
sounds easy enough, but the problem -- my RadGrid seems to be caching its DataSource. it always shows its initiate data and never updates, even tho when i step thru the code-behind i can see the new data
ASPX
C#
any idea whats going on here?
thanks!
matt
on my ASPX page I have two controls: a DropDownList, and a RadGrid. when the DropDownList posts back, I want to update the data in the RadGrid based on the list's current selected value.
sounds easy enough, but the problem -- my RadGrid seems to be caching its DataSource. it always shows its initiate data and never updates, even tho when i step thru the code-behind i can see the new data
ASPX
<!-- SELECT ROLE TO MANAGE --> |
Role to manage: <asp:DropDownList ID="ddlRoles" DataValueField="Name" DataTextField="Name" AutoPostBack="true" OnSelectedIndexChanged="ddlRoles_SelectedIndexChanged" runat="server" /> |
<div id="divEditUsersForm" style="margin-bottom:40px;" visible="true" runat="server"> |
<p>Users in Role:</p> |
<Telerik:RadGrid ID="gridRoleUsers" |
Skin="Office2007" |
GridLines="None" |
AllowPaging="true" |
PageSize="50" |
PagerStyle-Mode="NextPrevAndNumeric" |
AllowSorting="true" |
AutoGenerateColumns="False" |
AllowMultiRowSelection="true" |
AllowMultiRowEdit="true" |
OnDeleteCommand="gridRoleUsers_DeleteCommand" |
OnNeedDataSource="gridRoleUsers_NeedDataSource" |
OnPreRender="grid_PreRender" |
runat="server"> |
<ClientSettings |
EnableRowHoverStyle="true" |
AllowDragToGroup="false" |
AllowColumnsReorder="false" |
AllowKeyboardNavigation="true" |
ReorderColumnsOnClient="false" > |
<Resizing AllowColumnResize="false" AllowRowResize="false" /> |
<Selecting AllowRowSelect="true" EnableDragToSelectRows="true" /> |
</ClientSettings> |
<MasterTableView |
CommandItemDisplay="Top" |
DataKeyNames="Username" |
EditMode="InPlace" |
NoMasterRecordsText="No users to display." |
CommandItemStyle-Font-Bold="true" |
HeaderStyle-ForeColor="#191970" |
ItemStyle-ForeColor="black" |
AlternatingItemStyle-ForeColor="black"> |
<%-- use for support for multi edit/deletes > --%> |
<CommandItemTemplate> |
<div style="padding:3px 0px;"> |
<asp:LinkButton ID="btnDelete" CommandName="DeleteSelected" OnClientClick="javascript:return confirm('Remove all selected Users?')" CausesValidation="false" Visible='<%# !gridRoleUsers.MasterTableView.IsItemInserted && gridRoleUsers.EditIndexes.Count == 0 %>' CssClass="commandItem" runat="server"><img src="/images/delete.gif" width="16" height="16" border="0"/> Remove Selected Users</asp:LinkButton> |
</div> |
</CommandItemTemplate> |
<Columns> |
<Telerik:GridClientSelectColumn HeaderStyle-Width="24" HeaderStyle-HorizontalAlign="center" ItemStyle-HorizontalAlign="center" /> |
<Telerik:GridButtonColumn CommandName="Delete" ButtonType="LinkButton" Text="Remove" UniqueName="deleteColumn" ConfirmText="Remove user from Role?" ConfirmTitle="Delete" HeaderStyle-Width="40" ItemStyle-ForeColor="#333333" ItemStyle-Font-Bold="True" /> |
<Telerik:GridBoundColumn HeaderText="Username" UniqueName="Username" DataField="Username" HeaderStyle-Wrap="false" ReadOnly="true" /> |
<Telerik:GridBoundColumn HeaderText="Role Name" UniqueName="RoleName" DataField="RoleName" HeaderStyle-Wrap="false" ReadOnly="true" /> |
</Columns> |
</MasterTableView> |
</Telerik:RadGrid> |
</div> |
<Telerik:RadAjaxManager ID="radAjaxManager" runat="server"> |
<AjaxSettings> |
<%-- grid updates itself --%> |
<Telerik:AjaxSetting AjaxControlID="gridRoleUsers"> |
<UpdatedControls> |
<Telerik:AjaxUpdatedControl ControlID="gridRoleUsers" LoadingPanelID="ajaxLoadingPanel" /> |
<Telerik:AjaxUpdatedControl ControlID="lblMessage" /> |
</UpdatedControls> |
</Telerik:AjaxSetting> |
</AjaxSettings> |
</Telerik:RadAjaxManager> |
<Telerik:RadAjaxLoadingPanel ID="ajaxLoadingPanel" Width="75px" Height="75px" Transparency="10" runat="server"> |
<img alt="Loading..." src='<%= RadAjaxLoadingPanel.GetWebResourceUrl(Page, "Telerik.Web.UI.Skins.Default.Ajax.loading.gif") %>' style="border:0;" /> |
</Telerik:RadAjaxLoadingPanel> |
C#
protected void Page_Load(object sender, EventArgs e) |
{ |
//set header's help URL |
AutomaticVehicleLocator.controls.nav.Header ucHeader = (AutomaticVehicleLocator.controls.nav.Header)this.Master.FindControl("ucHeader"); |
ucHeader.HelpUrl = "~/helpUserManager.aspx"; |
if (!IsPostBack) |
{ |
ddlRoles.DataSource = GetRolesTable(); |
ddlRoles.DataBind(); |
} |
_role = ddlRoles.SelectedValue; |
} |
//''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' |
protected void ddlRoles_SelectedIndexChanged(object sender, EventArgs e) |
{ |
//_role = ddlRoles.SelectedValue; |
SetRoleUsersGridDataSource(); |
divEditUsersForm.Visible = true; |
//litRoleName.Text = _role; |
} |
/// <summary> |
/// Fired when grid needs a datasource. eg, after editing or deleting. |
/// </summary> |
protected void gridRoleUsers_NeedDataSource(object source, GridNeedDataSourceEventArgs e) |
{ |
SetRoleUsersGridDataSource(); |
} |
private void SetRoleUsersGridDataSource() |
{ |
gridRoleUsers.DataSource = null; |
if (Strings.Exists(_role)) |
{ |
// This event fails if a databind is specified - it has to do its own databind. |
gridRoleUsers.DataSource = GetUsersForRole(_role); |
} |
} |
any idea whats going on here?
thanks!
matt