PDA

View Full Version : [CLOSED] Filter a combobox from selected value other combobox.



luiz
Mar 14, 2014, 4:02 PM
Hi

I am using two combobox with httphandler.
I want to filter the second combobox with the first combobox value.

My complete test:

Class


using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace UploadBigFile
{
public class Blog
{
public int Id { get; set; }
public string Name { get; set; }

public static List<Blog> GetBlogs(string query)
{
return new List<Blog>()
{
new Blog(){Id=1, Name="Blog 1"},
new Blog(){Id=2, Name="Blog 2"},
new Blog(){Id=3, Name="Blog 3"}
}
.Where(a => a.Name.ToLower().StartsWith(query))
.ToList();
}
}
}


using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace UploadBigFile
{
public class Post
{
public int Id { get; set; }
public int Id_Post { get; set; }
public string Name { get; set; }

public static List<Post> GetPosts(string query, int idPost)
{
return new List<Post>()
{
//Blog 1
new Post(){Id=1, Name="Post 1 - Blog 1", Id_Post=1},
new Post(){Id=1, Name="Post 2 - Blog 1", Id_Post=1},
new Post(){Id=1, Name="Post 3 - Blog 1", Id_Post=1},

//Blog 2
new Post(){Id=1, Name="Post 1 - Blog 2", Id_Post=2},
new Post(){Id=1, Name="Post 2 - Blog 2", Id_Post=2},
new Post(){Id=1, Name="Post 3 - Blog 2", Id_Post=2},

//Blog 3
new Post(){Id=1, Name="Post 1 - Blog 3", Id_Post=3},
new Post(){Id=1, Name="Post 2 - Blog 3", Id_Post=3},
new Post(){Id=1, Name="Post 3 - Blog 3", Id_Post=3},
}
.Where(a => a.Name.ToLower().StartsWith(query) && a.Id_Post == idPost)
.ToList();
}
}
}


HttpHandlers


using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using Ext.Net;

namespace UploadBigFile
{
/// <summary>
/// Summary description for BlogsHandler
/// </summary>
public class BlogsHandler : IHttpHandler
{


public void ProcessRequest(HttpContext context)
{
context.Response.ContentType = "text/json";

string query = string.Empty;

if (!string.IsNullOrEmpty(context.Request["query"]))
{
query = context.Request["query"];
}

List<Blog> blogs = Blog.GetBlogs(query);

context.Response.Write(string.Format("{{total:{1},'blogs':{0}}}", JSON.Serialize(blogs), blogs.Count));
}

public bool IsReusable
{
get
{
return false;
}
}
}
}

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using Ext.Net;

namespace UploadBigFile
{
/// <summary>
/// Summary description for PostsHandler
/// </summary>
public class PostsHandler : IHttpHandler
{

public void ProcessRequest(HttpContext context)
{
context.Response.ContentType = "text/json";

int blog = 0;
int start = 0;
int limit = 10;
string query = string.Empty;

if (!string.IsNullOrEmpty(context.Request["blog"]))
{
blog = int.Parse(context.Request["blog"]);
}

if (blog > 0)
{
if (!string.IsNullOrEmpty(context.Request["start"]))
{
start = int.Parse(context.Request["start"]);
}

if (!string.IsNullOrEmpty(context.Request["limit"]))
{
limit = int.Parse(context.Request["limit"]);
}

if (!string.IsNullOrEmpty(context.Request["query"]))
{
query = context.Request["query"];
}

List<Post> posts = Post.GetPosts(query, blog);

context.Response.Write(string.Format("{{total:{1},'posts':{0}}}", JSON.Serialize(posts), posts.Count));
}
else
context.Response.Write(string.Format("{{total:{1},'posts':{0}}}", "[]", 0));

}

public bool IsReusable
{
get
{
return false;
}
}
}
}


aspx page


<%@ Page Language="C#" AutoEventWireup="true" %>

<%@ Register Assembly="Ext.Net" Namespace="Ext.Net" TagPrefix="ext" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>


<script runat="server">
protected void ComboBoxBlogs_Select(object sender, DirectEventArgs e)
{
this.ComboBoxPosts.Clear();

if (!string.IsNullOrEmpty(this.ComboBoxBlogs.Text))
{
this.Store2.SetProxyUrl("PostsHandler.ashx?blog=" + this.ComboBoxPosts.Text);
}
}
</script>

</head>

<body>
<form id="form1" runat="server">
<ext:ResourceManager ID="ResourceManager1" runat="server" />

<ext:FormPanel runat="server" Layout="FormLayout">
<Items>
<ext:ComboBox ID="ComboBoxBlogs"
runat="server"
DisplayField="Name"
FieldLabel="Blogs"
ValueField="Id"
TypeAhead="false"
Width="570"
PageSize="10"
HideBaseTrigger="true"
MinChars="0"
TriggerAction="Query">
<listconfig loadingtext="Searching...">
<ItemTpl runat="server">
<Html>
<div class="search-item">
<h3><span>{Name}</span>
</div>
</Html>
</ItemTpl>
</listconfig>
<Store>
<ext:Store ID="Store1" runat="server" AutoLoad="false">
<Proxy>
<ext:AjaxProxy Url="BlogsHandler.ashx">
<actionmethods read="POST" />
<reader>
<ext:JsonReader Root="blogs" TotalProperty="total" />
</reader>
</ext:AjaxProxy>
</Proxy>
<model>
<ext:Model runat="server">
<Fields>
<ext:ModelField Name="Id" />
<ext:ModelField Name="Name" />
</Fields>
</ext:Model>
</model>
</ext:Store>
</Store>
<DirectEvents>
<Select OnEvent="ComboBoxBlogs_Select">
<EventMask ShowMask="true" />
</Select>
</DirectEvents>
</ext:ComboBox>

<ext:ComboBox ID="ComboBoxPosts"
runat="server"
DisplayField="Name"
FieldLabel="Posts"
ValueField="Id"
TypeAhead="false"
Width="570"
PageSize="10"
HideBaseTrigger="true"
MinChars="0"
TriggerAction="Query">
<listconfig loadingtext="Searching...">
<ItemTpl runat="server">
<Html>
<div class="search-item">
<h3><span>{Name}</span>
</div>
</Html>
</ItemTpl>
</listconfig>
<Store>
<ext:Store ID="Store2" runat="server" AutoLoad="false">
<Proxy>
<ext:AjaxProxy Url="PostsHandler.ashx">
<actionmethods read="POST" />
<reader>
<ext:JsonReader Root="posts" TotalProperty="total" />
</reader>
</ext:AjaxProxy>
</Proxy>
<model>
<ext:Model runat="server">
<Fields>
<ext:ModelField Name="Id" />
<ext:ModelField Name="Name" />
</Fields>
</ext:Model>
</model>
</ext:Store>
</Store>
</ext:ComboBox>
</Items>
</ext:FormPanel>

</form>
</body>
</html>



In select event from first combobox I did this test, but no work...

this.Store2.SetProxyUrl("PostsHandler.ashx?blog=" + this.ComboBoxPosts.Text);


Any suggestion?

luiz
Mar 15, 2014, 1:02 PM
Please, close this thread.

Daniil
Mar 17, 2014, 5:37 AM
Sharing a solution can help others in the future.

luiz
Mar 20, 2014, 12:09 AM
My sample work fine!