I am trying to remove an item from our dropdown list before the data is bound. We have an API interface which is built linked to a Soap Service Client.
So we have the API client which is built in aspx and aspx.cs The dropdown list calls upon the datasource then binds the data to bringit up in the ddl. Below is the code I have.
using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; using System.Data; using System.Configuration;
namespace wsdl_ipop { public partial class CreateUser : System.Web.UI.Page { string apiKey = ConfigurationManager.AppSettings["apiKey"].ToString();
static string dlrCode = ""; static System.Data.DataSet dlrResponseData = new System.Data.DataSet(); static System.Data.DataSet uResponseData = new System.Data.DataSet();
I would suggest to remove the item first from the dataset and then bind it with the grid.
//Code to remove row
DataRow[] dr = _communicationDS.Tables[0].Select("Client ID = 22");
foreach (var dataRow in dr)
{
_communicationDS.Tables[0].Rows.Remove(dataRow);
}
Regards
Ankit
(Please select 'Mark as Answer' if my response has helped you.)
Ok I've tried the responses however it does not work for any. The client is still in the dropdown.
This is the beginning of the code in the aspx.cs, then you have the dropdown datasource call.
using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; using System.Data; using System.Configuration;
namespace wsdl_ipop { public partial class CreateUser : System.Web.UI.Page { string apiKey = ConfigurationManager.AppSettings["apiKey"].ToString();
static string dlrCode = ""; static System.Data.DataSet dlrResponseData = new System.Data.DataSet(); static System.Data.DataSet uResponseData = new System.Data.DataSet();
protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { API_Service.ipopSoapClient myAPI = new API_Service.ipopSoapClient(); System.Data.DataSet responseData = new System.Data.DataSet(); responseData = myAPI.getGlobals(apiKey);
What code should I put in to remove the entry in the ddlClient which contains a row called by text "Client UK". The value "Client UK" is in row 22 of the dropdown, Value ID is 22.
So what code and where would I put it in the code above? And do I have to put anything extra in the aspx file itself as well as the .cs
I don't want to delete the value in the database. Just remove it from the list itself in this dropdown. I need the complete list for another dropdown later on which is fine. It's just this dropdown I need it removed from the list.
But the suggestion with the code above again still does not remove it. So tad confused as I've tried everything before coming to you guys and I cannot get it to work still.
Do you reckon it may be anything to do with Soap behind the API?
ttldbonner
0 Points
9 Posts
C# Dropdown List - Item Removal
Jan 24, 2013 10:08 AM|LINK
I am trying to remove an item from our dropdown list before the data is bound. We have an API interface which is built linked to a Soap Service Client.
So we have the API client which is built in aspx and aspx.cs The dropdown list calls upon the datasource then binds the data to bringit up in the ddl. Below is the code I have.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Configuration;
namespace wsdl_ipop
{
public partial class CreateUser : System.Web.UI.Page
{
string apiKey = ConfigurationManager.AppSettings["apiKey"].ToString();
static string dlrCode = "";
static System.Data.DataSet dlrResponseData = new System.Data.DataSet();
static System.Data.DataSet uResponseData = new System.Data.DataSet();
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
API_Service.ipopSoapClient myAPI = new API_Service.ipopSoapClient();
System.Data.DataSet responseData = new System.Data.DataSet();
responseData = myAPI.getGlobals(apiKey);
ddlClient.DataSource = responseData;
ddlClient.DataTextField = "sb_name";
ddlClient.DataValueField = "sb_idno";
ddlClient.DataBind();
}
}
}
Now what i'd like to do is place the code in to remove the dropdown item that contains a text value of "Client UK". And/or Client ID Value of "22".
The code I compiled is like so however it doesnt remove the entry.
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
API_Service.ipopSoapClient myAPI = new API_Service.ipopSoapClient();
System.Data.DataSet responseData = new System.Data.DataSet();
responseData = myAPI.getGlobals(apiKey);
ddlClient.DataSource = responseData;
ddlClient.DataTextField = "sb_name";
ddlClient.DataValueField = "sb_idno";
ddlClient.Items.Remove("22");
ddlClient.items.Remove(Remove ListItem.Text("Client UK"));
ddlClient.DataBind();
}
}
protected void ddlClient_SelectedIndexChanged(object sender, EventArgs e)
{
foreach (ListItem li in ddlClient.Items)
{
if (ddlClient.SelectedItem.Text == li.Text)
{
ddlClient.Items.Remove(ddlClient.Items.FindByValue(22));
}
}
}
Any advice on why this entry has not been removed from the ddl?!
Thank you!
DarrellNorto...
All-Star
86773 Points
9643 Posts
Moderator
MVP
Re: C# Dropdown List - Item Removal
Jan 24, 2013 10:11 AM|LINK
Call DataBind() then remove the items.
Darrell Norton's Blog
Please click "Mark as Answer" if this helped you.
asp.netforum...
Member
604 Points
132 Posts
Re: C# Dropdown List - Item Removal
Jan 24, 2013 10:15 AM|LINK
hai
use RemoveAt() method
Sujeet Saste
Contributor
2998 Points
572 Posts
Re: C# Dropdown List - Item Removal
Jan 24, 2013 10:22 AM|LINK
Put this in your page load, after ddlClient.DataBind();
ddlClient.Items.Remove(ddlClient.Items.FindByValue("22"));Because FindByValue / FindByText accepts String as an argument.
Do FEAR (Face Everything And Rise)
Please mark as Answer if my post helps you..!
My Blog
goel.ankit
Contributor
2531 Points
513 Posts
Re: C# Dropdown List - Item Removal
Jan 24, 2013 10:24 AM|LINK
I would suggest to remove the item first from the dataset and then bind it with the grid.
//Code to remove row DataRow[] dr = _communicationDS.Tables[0].Select("Client ID = 22"); foreach (var dataRow in dr) { _communicationDS.Tables[0].Rows.Remove(dataRow); }Ankit
(Please select 'Mark as Answer' if my response has helped you.)
ttldbonner
0 Points
9 Posts
Re: C# Dropdown List - Item Removal
Jan 24, 2013 11:16 AM|LINK
Ok I've tried the responses however it does not work for any. The client is still in the dropdown.
This is the beginning of the code in the aspx.cs, then you have the dropdown datasource call.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Configuration;
namespace wsdl_ipop
{
public partial class CreateUser : System.Web.UI.Page
{
string apiKey = ConfigurationManager.AppSettings["apiKey"].ToString();
static string dlrCode = "";
static System.Data.DataSet dlrResponseData = new System.Data.DataSet();
static System.Data.DataSet uResponseData = new System.Data.DataSet();
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
API_Service.ipopSoapClient myAPI = new API_Service.ipopSoapClient();
System.Data.DataSet responseData = new System.Data.DataSet();
responseData = myAPI.getGlobals(apiKey);
ddlClient.DataSource = responseData;
ddlClient.DataTextField = "sb_name";
ddlClient.DataValueField = "sb_idno";
ddlClient.DataBind();
}
}
What code should I put in to remove the entry in the ddlClient which contains a row called by text "Client UK". The value "Client UK" is in row 22 of the dropdown, Value ID is 22.
So what code and where would I put it in the code above? And do I have to put anything extra in the aspx file itself as well as the .cs
Thank you,
Dan
Sujeet Saste
Contributor
2998 Points
572 Posts
Re: C# Dropdown List - Item Removal
Jan 24, 2013 11:24 AM|LINK
Use following code, and also debug the code and check for all values just for sure.
protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { API_Service.ipopSoapClient myAPI = new API_Service.ipopSoapClient(); System.Data.DataSet responseData = new System.Data.DataSet(); responseData = myAPI.getGlobals(apiKey); ddlClient.DataSource = responseData; ddlClient.DataTextField = "sb_name"; ddlClient.DataValueField = "sb_idno"; ddlClient.DataBind(); ddlClient.Items.Remove(ddlClient.Items.FindByText("Client UK")); } }Please check and let us know...
Do FEAR (Face Everything And Rise)
Please mark as Answer if my post helps you..!
My Blog
asp.netforum...
Member
604 Points
132 Posts
Re: C# Dropdown List - Item Removal
Jan 24, 2013 11:25 AM|LINK
simply u like delete the value in your database.
shivanand G ...
Participant
1763 Points
534 Posts
Re: C# Dropdown List - Item Removal
Jan 24, 2013 11:26 AM|LINK
protected void ddlClient_SelectedIndexChanged(object sender, EventArgs e) { API_Service.ipopSoapClient myAPI = new API_Service.ipopSoapClient(); System.Data.DataSet responseData = new System.Data.DataSet(); responseData = myAPI.getGlobals(apiKey); responseData .tables[o].rows["+ddlClient.selectedindex.tostring()+"].delete(); ddlClient.DataSource = responseData; ddlClient.DataTextField = "sb_name"; ddlClient.DataValueField = "sb_idno"; ddlClient.Items.Remove("22"); ddlClient.DataBind(); }shivanand.G.N (shivu.betta@gmail.com)
ttldbonner
0 Points
9 Posts
Re: C# Dropdown List - Item Removal
Jan 24, 2013 11:59 AM|LINK
I don't want to delete the value in the database. Just remove it from the list itself in this dropdown. I need the complete list for another dropdown later on which is fine. It's just this dropdown I need it removed from the list.
But the suggestion with the code above again still does not remove it. So tad confused as I've tried everything before coming to you guys and I cannot get it to work still.
Do you reckon it may be anything to do with Soap behind the API?