Aug 03, 2011, 4:51 PM
[CLOSED] Problem when using combobox with autorefreshdata and asp:dropdownlist
I have the following situation in a page:
- There is a combobox in which i use onrefreshdata, so that when the user types anything it's content is filtered in the server.
- There is an asp:DropDownList. In this case i must use it instead of a combobox or selectbox because it renders as a html "select", and this page is used by our clients under ipad (ipad's safari has it's own way of letting the user choose an item from an html select, if i use a combobox or selectbox it functions the same way as on the pc, and it's hard to choose the items using the fingers).
- When a value is selected in the combobox (change directevent), i need to change the content of the dropdownlist accoridng to the item that was selected in the combobox.
- It works fine the first time, but then, if i try to type another thing in the combobox, i'm presented with a 500 server error.
Any idea on what might be wrong?
Follows an example:
.aspx:
.aspx.cs:
- There is a combobox in which i use onrefreshdata, so that when the user types anything it's content is filtered in the server.
- There is an asp:DropDownList. In this case i must use it instead of a combobox or selectbox because it renders as a html "select", and this page is used by our clients under ipad (ipad's safari has it's own way of letting the user choose an item from an html select, if i use a combobox or selectbox it functions the same way as on the pc, and it's hard to choose the items using the fingers).
- When a value is selected in the combobox (change directevent), i need to change the content of the dropdownlist accoridng to the item that was selected in the combobox.
- It works fine the first time, but then, if i try to type another thing in the combobox, i'm presented with a 500 server error.
Any idea on what might be wrong?
Follows an example:
.aspx:
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs" Inherits="WSMXM.WebForm1" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<ext:ResourceManager runat="server"></ext:ResourceManager>
<ext:ComboBox FieldLabel="Nome Fantasia" ID="myComboBox" runat="server" DisplayField="DS"
ValueField="VALUE" TypeAhead="false" LoadingText="Buscando..." MinChars="1" HideTrigger="true"
Width="280">
<Store>
<ext:Store ID="Store1" runat="server" AutoLoad="false" OnRefreshData="Store_Refresh">
<Proxy>
<ext:PageProxy />
</Proxy>
<Reader>
<ext:JsonReader>
<Fields>
<ext:RecordField Name="DS" Type="String" />
<ext:RecordField Name="VALUE" Type="String" />
</Fields>
</ext:JsonReader>
</Reader>
</ext:Store>
</Store>
</ext:ComboBox>
<asp:DropDownList Width="200" Height="22" runat="server" ID="myDropDownList">
</asp:DropDownList>
</div>
</form>
</body>
</html>
.aspx.cs:
public partial class WebForm1 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
myComboBox.DirectEvents.Change.Event += new ComponentDirectEvent.DirectEventHandler(Change_Event);
}
void Change_Event(object sender, DirectEventArgs e)
{
myDropDownList.Items.Clear();
myDropDownList.Items.Add(myComboBox.Value.ToString());
myDropDownList.Update();
}
protected void Store_Refresh(object sender, StoreRefreshDataEventArgs e)
{
System.Data.DataTable dt = new System.Data.DataTable();
dt.Columns.Add("DS");
dt.Columns.Add("VALUE");
System.Data.DataRow dr = dt.NewRow();
dr["DS"] = "ABC";
dr["VALUE"] = "1";
dt.Rows.Add(dr);
dr = dt.NewRow();
dr["DS"] = "DEF";
dr["VALUE"] = "2";
dt.Rows.Add(dr);
Store store = sender as Store;
string filter = e.Parameters["query"];
if (filter.Equals("."))
{
store.DataSource = dt;
store.DataBind();
return;
}
var filteredList = (from x in dt.AsEnumerable()
where (x["DS"]).ToString().ToUpper().StartsWith(filter.ToUpper())
select new { VALUE = x["VALUE"].ToString(), DS = x["DS"].ToString() }
);
store.DataSource = filteredList;
store.DataBind();
}
}
Last edited by Daniil; Aug 04, 2011 at 8:22 PM.
Reason: [CLOSED]