如何抵抗下拉值. [英] How to resist the drop down value.
本文介绍了如何抵抗下拉值.的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个下拉列表和2个列表框.我希望我无法从列表框1和2中选择任何内容,直到我没有从dropdownlist中选择任何内容,但是每次我从dropdownlist中选择任何内容时,它都会回发并且其值不能抵抗.
I have a drop downlist and 2 list box . I want that i am not able to select anything from listbox 1 and 2 until i am not selecting the item from dropdownlist but every time i select anything from dropdownlist it postback and its value is not resisting .
<div>
<asp:DropDownList ID="ddlAdmin" runat="server" >
<table width="70%">
<tr><td colspan="3">
<asp:ListBox ID="ProductListBox" runat="server" SelectionMode="Multiple" ></td>
<td><asp:Button ID="BtnMoveLeft" runat="server" Text="Add Permission" OnClick="BtnMoveleft_Click" /></td>
<td>
<asp:ListBox ID="PermissionListBox" runat="server" SelectionMode="Multiple" ></td>
</tr>
</table>
</div>
protected void Page_Load(object sender, EventArgs e)
{
FillProductList();
FillAdminDropDownList();
}
protected void FillAdminDropDownList()
{
DataManager myData = new DataManager(DbFunctions.GetConnectionString());
MySqlConnection myPConn = myData.GetPooledConnection(new MySqlConnection());
MySqlCommand cmd = new MySqlCommand("SELECT adminuserid,adminusername FROM adminusermast", myPConn);
DataTable dt = new DataTable();
myPConn.Open();
MySqlDataAdapter adptr = new MySqlDataAdapter(cmd);
adptr.Fill(dt);
myPConn.Close();
if (dt.Rows.Count > 0)
{
ddlAdmin.Items.Clear();
ddlAdmin.Items.Add("SELECT");
foreach (DataRow drow in dt.Rows)
{
ListItem lst = new ListItem();
lst.Value = drow[1].ToString();
lst.Text = drow[0].ToString();
ddlAdmin.Items.Add(lst);
}
}
}
protected void FillProductList()
{
DataManager myData = new DataManager(DbFunctions.GetConnectionString());
MySqlConnection myPConn = myData.GetPooledConnection(new MySqlConnection());
MySqlCommand com = new MySqlCommand("Select productid,productname from productmast", myPConn);
MySqlDataReader Reader = null;
myPConn.Open();
Reader = com.ExecuteReader();
while (Reader.Read())
{
ListItem newItem = new ListItem();
newItem.Text = Reader["productname"].ToString();
newItem.Value = Reader["productid"].ToString();
ProductListBox.Items.Add(newItem);
}
Reader.Close();
myPConn.Close();
}
protected void BtnMoveleft_Click(object sender, EventArgs e)
{
for (int i = ProductListBox.Items.Count - 1; i >= 0; i--)
{
if (ProductListBox.Items[i].Selected == true)
{
PermissionListBox.Items.Add(ProductListBox.Items[i]);
ListItem li = ProductListBox.Items[i];
ProductListBox.Items.Remove(li);
}
}
}
推荐答案
最初设置DropDownList.Enabled ="false"
在DropDownList2_SelectedIndexChanged
中 {
DropDownList1.Enabled ="true";
}
initially set DropDownList.Enabled="false"
in the DropDownList2_SelectedIndexChanged
{
DropDownList1.Enabled="true";
}
如果可能将您的下拉列表放在更新面板"中.....
Hi ,
If Possibly Put Your dropdownlist in Update Panel.....
这篇关于如何抵抗下拉值.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文