Click here to Skip to main content
15,925,255 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have a dropdownlistbox in which data is coming from user table and it bind the data when !IsPostBack . I have two listbox in which one contain the items and other is for adding the items .

Everything is working when i select the user it shows two list boxes and i swap items from 1 to other and on submit they entered into database . But problem arises when i done it for second time or reselect the user from dropdown box .

I already added the items in the list box on the dropdown OnSelectedIndexChange .
Posted
Updated 19-Oct-11 22:23pm
v2
Comments
shek124 20-Oct-11 4:29am    
Provide the code
Vimalrashamra 20-Oct-11 4:55am    
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
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[0].ToString();
lst.Text = drow[1].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 * from productmast where productid NOT IN (select productid from userpermission where adminuserid =" + ddlAdmin.SelectedIndex.ToString() + ")", 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 FillProuductPermissionList()
{
DataManager myData = new DataManager(DbFunctions.GetConnectionString());
MySqlConnection myPConn = myData.GetPooledConnection(new MySqlConnection());
MySqlCommand com = new MySqlCommand("select * from userpermission u inner join productmast p on u.productid = p.productid where adminuserid =" + ddlAdmin.SelectedIndex.ToString() + "", 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();
PermissionListBox.Items.Add(newItem);
}
Reader.Close();
myPConn.Close();
Response.Write(ddlAdmin.SelectedIndex.ToString());
}
protected void AdminDropDown_Selected(object sender, EventArgs e)
{
FillProductList();
ProductListBox.Visible = true;
BtnMoveLeft.Visible = true;
ButtonMoveRight.Visible = true;
PermissionListBox.Visible = true;
FillProuductPermissionList();
}
protected void BtnMoveleft_Click(object sender, EventArgs e)
{
if (ProductListBox.SelectedIndex == -1)
{
LabelError.InnerHtml = "No Data Selected";
}
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);
}
}
BtnPermission.Enabled = true;

}
protected void Permission_Accepted(object sender, EventArgs e)
{
DataManager myData = new DataManager(DbFunctions.GetConnectionString());
MySqlConnection myPConn = myData.GetPooledConnection(new MySqlConnection());
for(int i=PermissionListBox.Items.Count-1;i>=0;i--)
{
AswinKrishnan 21-Oct-11 2:50am    
Hi VRdwivedi,

Can you provide the HTML of the DropDownList and code for OnSelectedIndexChange ?

1 solution

Hi,

What is happening when click for second time,please be more specific.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900