Hi J. I am not sure if i understand it correctly but you wanna make sure that that item in your dropdown does not exist in your gridview right? please find my solution below, though I was so lazy to create a db sample of data so i just manually created it for example purposes.
this is my aspx:
<asp:GridView ID="myGrid" runat="server" AutoGenerateColumns="false">
<Columns>
<asp:BoundField DataField="Id" HeaderText="id" />
<asp:BoundField DataField="Value" HeaderText="value" />
</Columns>
</asp:GridView>
<asp:DropDownList ID="mydropdown" runat="server">
</asp:DropDownList>
code behind:
you basically need an entity, like a class that represent your table structure:
public class MyEntity
{
public MyEntity(string id, string value)
{
ID = id;
Value = value;
}
public string ID { get; set; }
public string Value { get; set; }
}
a page load event handler that calls method to prefill your controls
protected void Page_Load(object sender, EventArgs e)
{
this.FillGrid();
this.FillDropdownUsingGenericList();
}
Manually added function to prefill your controls. this is being called in page load event
private void FillDropdownUsingGenericList()
{
this.mydropdown.DataTextField = "Value";
this.mydropdown.DataValueField = "Id";
this.mydropdown.DataSource = this.DropdownSource();
this.mydropdown.DataBind();
}
private void FillGrid()
{
this.myGrid.DataSource = this.GridSource();
this.myGrid.DataBind();
}
Just imagine this as the data that's coming from your database and thus return a generic list of your entity. this is the datasource for your gridview:
//function that's responsible of identifying the data to be loaded in your gridview
private List<MyEntity> GridSource()
{
List<MyEntity> list = new List<MyEntity>();
list.Add(new MyEntity("ID1", "Boy"));
list.Add(new MyEntity("ID3", "Bakla"));
list.Add(new MyEntity("ID5", "Bata"));
return list;
}
This is the IMPORTANT FUNCTION, the following is your data source for your dropdown. inside this function it filters the data to be displayed in your dropdown and these data must not exist in the gridview
//function that's responsible identifying the data to be loaded in your dropdown
private List<MyEntity> DropdownSource()
{
//dropdown source
List<MyEntity> dropdownlist = new List<MyEntity>();
dropdownlist.Add(new MyEntity("ID1", "Boy"));
dropdownlist.Add(new MyEntity("ID2", "Girl"));
dropdownlist.Add(new MyEntity("ID3", "Bakla"));
dropdownlist.Add(new MyEntity("ID4", "Tomboy"));
dropdownlist.Add(new MyEntity("ID5", "Bata"));
dropdownlist.Add(new MyEntity("ID6", "Matanda"));
dropdownlist.Add(new MyEntity("ID7", "Hayop"));
//grid view source
List<MyEntity> gridList = (List<MyEntity>)this.myGrid.DataSource;
//before binding the dropdown source to the dropdown you have to remove items that was already in the gridview
var x = from d in dropdownlist
join g in gridList
on d.ID equals g.ID into leftJoined
where !leftJoined.Any()
select d;
return x.ToList<MyEntity>();
}
If this does not address your problem, my apology if i misunderstood ur requirements...
please lemme know if this one address ur problem and if not please lemme know what am i missing. :)
cheers..