How to filter the dropdown values? [Resolved]

Posted by Annagoldtech under VB.NET on 4/25/2013 | Points: 10 | Views : 1303 | Status : [Member] | Replies : 3
Hi,

I have a dropdown called Category eg: say values cat 1,cat 2,cat3. I m calling these values through Stored Procedures.

That stored procedure is used in other modules also.

My requirement is: in my particular module, the dropdown values "Cat 3" should not show.
I need to filter this value at my vb.net code behind.
How to resolve this issue?

Thanks.




Responses

Posted by: Santhi on: 4/26/2013 [Member] Starter | Points: 50

Up
0
Down

Resolved
Hi

Try this:
For example
Ui Design should be
 <form id="form1" runat="server">

<div>
<asp:Button ID="Button1" runat="server" Text="Button" OnClick="Button1_Click" />
<asp:DropDownList ID="DropDownList1" runat="server"></asp:DropDownList>
</div>

</form>


Code behind: CS

 public partial class WebForm1 : System.Web.UI.Page

{
protected void Page_Load(object sender, EventArgs e)
{if(!IsPostBack)
{
LoadDropdown();
}
}

private void LoadDropdown()
{
ListItem ab = new ListItem();
ab.Text = "hi";
ab.Value = "1";
DropDownList1.Items.Add(ab);
ab = new ListItem();
ab.Text = "hello";
ab.Value = "2";
DropDownList1.Items.Add(ab);

}

protected void Button1_Click(object sender, EventArgs e)
{

DropDownList1.Items.Remove(DropDownList1.Items.FindByText("hello"));


}
}


Thanks & Regards,
Santhi .V

Annagoldtech, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Santhi on: 4/26/2013 [Member] Starter | Points: 50

Up
0
Down

Resolved
Hi

Syntax to remove the listitem from the dropdownlist :

 DropDownList1.Items.Remove(DropDownList1.Items.FindByText("hello")); 

DropDownList1.Items.Remove(DropDownList1.Items.FindByText("hello"));
DropDownList1.Items.Remove(DropDownList1.Items.FindByValue("3"))
;


Thanks & Regards,
Santhi .V

Annagoldtech, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Annagoldtech on: 4/26/2013 [Member] Starter | Points: 25

Up
0
Down
Thanks a lot.
It works.

Annagoldtech, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response