Click here to Skip to main content
15,884,388 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
C#
 <asp:DropDownList runat="server" ID="ddlRole" AutoPostBack="true" OnSelectedIndexChanged="ddlRole_SelectedIndexChanged">

  <asp:ListItem Value="Master user" Text="Aby">
</asp:ListItem>
    <asp:ListItem Value="Master user" Text="Sanjay">
     </asp:ListItem>
<asp:ListItem Value="Master user" Text="Raymond">
      </asp:ListItem>
   <asp:ListItem Value="Master user" Text="Melvyn">
              </asp:ListItem>
    </asp:DropDownList>


Whenever ddlRole_SelectedIndexChanged fir its shows me slected text as Aby

Please help
Posted
Updated 11-Jun-13 23:40pm
v2
Comments
Prasad_Kulkarni 12-Jun-13 4:04am    
..what exactly you want? what you're expecting on selected index change of ddl
Member-515487 12-Jun-13 4:46am    
if i select Sanjay or Raymond or Melvyn it
it always show be selected Text as Aby becuase of same value

1 solution

C#
protected void ddlRole_SelectedIndexChanged(object sender, EventArgs e) 
{ 
string _selectedText = ddlRole.SelectedItem.Text;//to get the text of selected item
if (ddlRole.SelectedItem.Value != "Operational user") 
{ 
txtUser.ReadOnly = true; 
txtUser.Text = ddlRole.SelectedItem.Text; 
ScriptManager.RegisterClientScriptBlock(Page, GetType(), "Disable", "Disable()", true); 
} 
else 
{ 
txtUser.ReadOnly = false; 
txtUser.Text = ""; 
ScriptManager.RegisterClientScriptBlock(Page, GetType(), "Enable", "Enable()", true); 
} 
ddlRole.Items.FindByText(_selectedText).Selected = true;
} 
 
Share this answer
 
v2
Comments
Member-515487 12-Jun-13 4:46am    
if i select Sanjay or Raymond or Melvyn it
it always show be selected Text as Aby becuase of same value
Zafar Sultan 12-Jun-13 5:36am    
Post your complete code and elaborate the expected behavior.
Member-515487 12-Jun-13 5:39am    
because of same Vale field in more than 1 list item

when triggers fires ddlRole_SelectedIndexChanged its always shows me 1 st value as a selected one
Zafar Sultan 12-Jun-13 5:47am    
Post the code you have written for ddlRole_SelectedIndexChanged event.
Member-515487 12-Jun-13 6:07am    
protected void ddlRole_SelectedIndexChanged(object sender, EventArgs e)
{
if (ddlRole.SelectedItem.Value != "Operational user")
{
txtUser.ReadOnly = true;
txtUser.Text = ddlRole.SelectedItem.Text;
ScriptManager.RegisterClientScriptBlock(Page, GetType(), "Disable", "Disable()", true);
}
else {
txtUser.ReadOnly = false;
txtUser.Text = "";
ScriptManager.RegisterClientScriptBlock(Page, GetType(), "Enable", "Enable()", true);
}
}

its always shows me aby selected

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