PDA

View Full Version : [CLOSED] how to get the selected combobox's value which combobox is in webusercontrol



hdsoso
May 18, 2014, 3:07 PM
i want to resuse a combobox, so i place combobx into an usercontrol, but how to get the selected combobox's selected value where the page uses the usercontrol?


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

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title></title>
<script runat="server">
protected void Page_Load(object sender, EventArgs e)
{

}
protected void Click(object sender, DirectEventArgs e)
{
//here how to get the selected combobox's value?
}


</script>
</head>
<body>
<form id="form1" runat="server">
<ext:ResourceManager runat="server"></ext:ResourceManager>
<ext:UserControlLoader runat="server" ID="ucl_area" Path="WebUserControl1.ascx" />
<ext:Button runat="server">
<DirectEvents>
<Click OnEvent="Click"></Click>
</DirectEvents>
</ext:Button>
</form>
</body>
</html>


WebUserControl1.ascx


<%@ Control Language="C#" %>
<script runat="server">
protected void Page_Load(object sender, EventArgs e)
{
s_city.DataSource = new object[]
{
new {id = "1", city = "handan"},
new {id = "2", city = "sjz"}
};
s_city.DataBind();
}
</script>
<ext:ComboBox runat="server" ID="cb_city" FieldLabel="市" DisplayField="city" ValueField="id">
<Store>
<ext:Store runat="server" ID="s_city">
<Model>
<ext:Model runat="server">
<Fields>
<ext:ModelField Name="id"></ext:ModelField>
<ext:ModelField Name="city"></ext:ModelField>
</Fields>
</ext:Model>
</Model>
</ext:Store>
</Store>
</ext:ComboBox>

Daniil
May 19, 2014, 6:26 AM
Hi @hdsoso,

In this scenario you could use X.GetCmp.

X.GetCmp<ComboBox>("ComboBoxID").SelectedItem

To know a ComboBox's ID you should set up:

<ext:UserControlLoader ... UserControlID="UserControl1" />

Then

X.GetCmp<ComboBox>("UserControl1_cb_city").SelectedItem