How jquery cascade plugin bind with dataset?
Hi
I tried to use the jquery plugin at
http://plugins.jquery.com/project/cascade
and use the demo example code
http://dev.chayachronicles.com/jquery/c ... index.html
Update More Than One Child, each with their own datasource
The following code did not show any js error on firefox. However, city datalist became disable when i select province.
How should I fix it?
-
ASPX page:
<asp:DropDownList ID="province2" runat="server" />
<asp:DropDownList ID="city2" runat="server" />
VC#:
private void Bind_Province()
{
DataSet objDS;
string strSql = "SELECT id, province from province order by id asc";
objDS = SqlHelper.ExecuteDataset(DBConnection.ConnString, CommandType.Text, strSql);
this.province2.DataSource = objDS;
this.province2.DataTextField = "province";
this.province2.DataValueField = "id";
this.province2.DataBind();
this.province2.SelectedValue = "1";
}
JS:
function commonTemplate(item) {
return "<option value='" + item.Value + "'>" + item.Text + "</option>";
};
function commonMatch(selectedValue) {
return this.When == selectedValue;
};
jQuery(document).ready(function()
{
jQuery("#ctl00_cphContent_city2")
.cascade("#ctl00_cphContent_province2",{
ajax: {url: 'WebService.asmx/BindCity' },
template: commonTemplate,
match: commonMatch
});
});
CSS:
<style type="text/css">
.cascade-loading
{
background: transparent url("indicator.gif") no-repeat center;
}
</style>
WS:
[WebMethod]
[ScriptMethod(UseHttpGet = false)]
public DataSet BindCity(string provinceid)
{
DataSet ds = GetCity(provinceid);
return ds;
}
public DataSet GetCity(string provinceid)
{
DataSet ds = new DataSet();
try
{
using (SqlConnection Connection = new SqlConnection(ConnectionString))
{
string commandstring = "SELECT id, city from city where provinceid='" + provinceid + "' order by id asc";
using (SqlCommand command = new SqlCommand(commandstring, Connection))
{
command.CommandType = CommandType.Text;
Connection.Open();
try
{
command.ExecuteNonQuery();
}
catch (Exception ex)
{
string e = ex.Message;
command.Dispose();
Connection.Close();
}
finally
{
command.Dispose();
Connection.Close();
}
SqlDataAdapter da = new SqlDataAdapter(command);
da.Fill(ds);
return ds;
}
}
}
catch (SqlException ex)
{
string e = ex.Message;
return ds;
}
}