I'm having trouble re- DataBinding a combobox on a button click event. On the initial page load I'm binding the combobox (this works fine) which holds report settings. I'm allowing the user to type in a value on the combobox which enables a save link button. When the user clicks on the link button, I save all the report criteria off to the database and want to DataBind the combobox so show the newly added Item to the list. I've debugged the process and show that the new item is getting saved off to the database, the database is returning all items (including newly added). It also appears that new item is getting bound to the combobox but it does not display in the browser.
Aspx:
Code behind:
Aspx:
<table border="0" cellpadding="0" cellspacing="0" style="background-color:White;"> |
<tr> |
<td style="padding-right:5px;"><asp:LinkButton ID="lnkbtnSave" runat="server" Enabled="false" OnClick="lnkbtnSave_Click">Save</asp:LinkButton></td> |
<td style="padding-right:5px;"><asp:LinkButton ID="lnkbtnSaveAs" Enabled="false" runat="server" OnClick="lnkbtnSave_Click">Save As...</asp:LinkButton></td> |
<td><telerik:RadComboBox ID="rcbRptSettings" runat="server" AllowCustomText="true" EmptyMessage="My Reports" LoadingMessage="Loading..." OnSelectedIndexChanged="rcbRptSettings_SelectedIndexChanged" AutoPostBack="true" Skin="Outlook" Width="250px"></telerik:RadComboBox></td> |
<td style="padding-left:5px;"><asp:LinkButton ID="lnkbtnDelete" runat="server" OnClientClick="return blockConfirm('Are you sure you want to delete this report?', event, 330, 100,'','AARates Delete My Report');" OnClick="lnkbtnDelete_Click" Enabled="false">Delete</asp:LinkButton></td> |
</tr> |
</table> |
Code behind:
protected void Page_Load(object sender, EventArgs e) |
{ |
if (!Page.IsPostBack) |
{ |
BindSavedSettings(Master.loggedUser.UserReports); |
} |
} |
private void BindSavedSettings(List<UserReport> urReports) |
{ |
rcbRptSettings.DataSource = urReports; //Master.loggedUser.UserReports; |
rcbRptSettings.DataTextField = "Name"; |
rcbRptSettings.DataValueField = "UserReportID"; |
rcbRptSettings.DataBind(); |
rcbRptSettings.Items.Insert(0, new RadComboBoxItem("", "")); |
} |
protected void lnkbtnSave_Click(Object sender, EventArgs e) |
{ |
//Saves existing report |
bool settingsfound = false; |
UserReport ursettings; |
PgMessage.ClearMessages(); |
if (rcbRptSettings.Text != string.Empty) |
{ |
//USED FOR GRID SETTINGS |
//string grsettings = string.Empty; |
//GridSettingsPersister persister = new GridSettingsPersister(ARGrid1); |
//grsettings = persister.SaveSettings(); |
foreach (UserReport ur in Master.loggedUser.UserReports) |
{ |
if (ur.Name == rcbRptSettings.Text) |
{ |
settingsfound = true; |
} |
} |
if (settingsfound) |
{ |
ursettings = UserReport.getByKey(Convert.ToInt32(rcbRptSettings.SelectedValue)); |
SaveReportSettings(ursettings); |
} |
else |
{ //NEW Report Settings |
ursettings = new UserReport(); |
SaveReportSettings(ursettings); |
List<UserReport> urpt = UserReport.getByUserid(Master.loggedUser.Userid); |
BindSavedSettings(urpt); //BindSavedSettings to add new report setting |
} |
} |
else |
{ |
PgMessage.DisplayMessage(PageMessage.MessageType.Information, "Report Setting name must be entered"); |
} |
} |