Jan 11, 2018, 9:11 AM
[CLOSED] Problem Setting a ComboBox Value
Hi,
My problem is that I cant set a default ComboBox value without a page load.
Here is an example with a delailed explanation below.
.aspx:
I want to do this, without reloading the page and use a session variable.
Thank you for your time.
My problem is that I cant set a default ComboBox value without a page load.
Here is an example with a delailed explanation below.
.aspx:
<%@ Page Title="Extranet Jhayber" Language="C#"
CodeBehind="Pruebaextnet.aspx.cs" Inherits="Extranet.Pruebaextnet" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<%@ Register Assembly="Ext.Net" Namespace="Ext.Net" TagPrefix="ext" %>
<%@ Import Namespace="System.Collections.Generic" %>
<%@ Import Namespace="System.Xml" %>
<html>
<head>
</head>
<body>
<form runat="server">
<ext:ResourceManager runat="server" />
<ext:Viewport ID="Viewport1" runat="server" Layout="columnlayout" AutoScroll="true" >
<Items>
<ext:Panel runat="server" id="panel1" ColumnWidth="1" Height="800" Frame="true">
<Items>
<ext:ComboBox
id="ComboExample"
runat="server"
FieldLabel="Select a single state"
DisplayField="abbr"
Width="320"
LabelWidth="130"
QueryMode="Local"
TypeAhead="true"
ValueField="abbr">
<Store>
<ext:Store runat="server" id="Storecombo" AutoDataBind="true">
<Model>
<ext:Model runat="server">
<Fields>
<ext:ModelField Name="abbr" />
<ext:ModelField Name="name" />
<ext:ModelField Name="slogan" />
</Fields>
</ext:Model>
</Model>
<Reader>
<ext:ArrayReader />
</Reader>
</ext:Store>
</Store>
</ext:ComboBox>
<ext:Button runat="server" ID="button" Text="Combo default">
<DirectEvents>
<Click OnEvent="changecombo"></Click>
</DirectEvents>
</ext:Button>
</Items>
</ext:Panel>
</Items>
</ext:Viewport>
</form>
</body>
</html>
aspx.cs:namespace Extranet
{
public partial class Pruebaextnet : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
Storecombo.DataSource = TestData;
Storecombo.DataBind();
string defaultvalue = (string)(Session["default"]);
if(!string.IsNullOrEmpty(defaultvalue))
{
this.ComboExample.SelectedItems.Add(new Ext.Net.ListItem() { Value = defaultvalue });
}
}
protected void changecombo(object sender, EventArgs e)
{
this.ComboExample.SelectedItems.Add(new Ext.Net.ListItem() { Value = "AL" });
Session["default"] = "AL";
}
private object TestData
{
get
{
return new object[]
{
new object[] { "AL", "Alabama", "The Heart of Dixie" },
new object[] { "AK", "Alaska", "The Land of the Midnight Sun" },
new object[] { "AZ", "Arizona", "The Grand Canyon State" },
new object[] { "AR", "Arkansas", "The Natural State" },
new object[] { "CA", "California", "The Golden State" },
};
}
}
}
}
What I want to do is to set the default value "AL" when I press the button, but this is not working. However, as you can see in the example, If I create a session with the default value "AL" and I do the same in the pageload, if i reload the page, It works nice.I want to do this, without reloading the page and use a session variable.
Thank you for your time.