GridView Binding?

M

mateo

Hello,

I have a GridView inside which i want to show 3 dropdownList (one for
each Column).
So i've created 3 TemplateField

Continent
Country
City

1 -In the item Template i've drop a dropdownList for each one with a
corresponding ObjectDataSource (Which return a TableAdapter) and bind's
to the dropdowlist. Now if i don't bind a datasource to the gridview i
see nothing (no lines, no gridview, nothing). If i bind one of my
ObjectDataSource to it, the result is that i see the same number of
lines in the gridview that there is rows in the ObjectDataSource
binding to it. I want only one line (so that the user choose Continent
and then Country and finally City). So i made a struct containing 3
id's (ContinentId, CountryId, CityId) and a generic list of that struc
which i first populate with one default struct and then bind it to the
gridview. This way i have only one line in my gridview whith my 3
columns olding dropdowlist and i'm happy! the problem is my list is
always cleared ? Is there a way i can get the values selected in those
dropdownlist to be stored in my struct? (just though maybe i should use
object!)

2 - Also i want the second dropdownList to be filtered by the selection
of the first one, and the third by the selection of the second one. I'm
trying to use the FilterParameter but cannot seem to see my
dropdownlist object (they are in the itemTemplate). Is there a way i
can manage to get them ?

3 - Also when using the FilterParameters, (on two other dropdownlist
not in any gridview) the second dropdownlist will filter ok but never
clear it's list between changes of the first one ? so each time the
selectedValue of the first one change items are added to the second
one? Any Clues ?

Thanks for you help .
Mateo
 
M

mateo

Thanks for your example, it help me in some part but i still can't
figure out what's wrong with the second dropdownlist not filtering
right ?
It does the first time ok but all the succedent change in the first
list just add more and more items to the second ?

here is my code

<%--first list--%>
<asp:Label ID="LabelListClient" runat="server" Text="Client : "
Width="123px" meta:resourcekey="LabelListClientResource1"></asp:Label>
<asp:DropDownList ID="DropDownListClients" runat="server"
DataSourceID="ObjectDataSourceClients"
DataTextField="ClientName" DataValueField="ClientId"
Width="205px" AppendDataBoundItems="True" AutoPostBack="True">
<asp:ListItem Value="0">- Select a Client -</asp:ListItem>

<%--second list--%>
</asp:DropDownList>
<asp:Label ID="LabelListContact" runat="server" Text="Contact
:" Width="74px" ></asp:Label>
<asp:DropDownList ID="DropDownListContact" runat="server"
Width="246px" AppendDataBoundItems="True"
DataSourceID="ObjectDataSourceContacts" DataTextField="LastName"
DataValueField="ContactId">
<asp:ListItem Value="0">- Select a Contact -</asp:ListItem>
</asp:DropDownList>

<%--contact ObjetcDataSource--%>
<asp:ObjectDataSource ID="ObjectDataSourceContacts"
runat="server"
OldValuesParameterFormatString="original_{0}"
SelectMethod="GetData"
TypeName="dsMiscDataTableAdapters.ContactsTableAdapter"
FilterExpression="ClientId={0}" EnableCaching="True">
<FilterParameters>
<asp:ControlParameter ControlID="DropDownListClients"
DefaultValue="0" Name="ClientId"
PropertyName="SelectedValue" Type="Int64" />
</FilterParameters>
</asp:ObjectDataSource>

<%--client ObjetcDataSource--%>
<asp:ObjectDataSource ID="ObjectDataSourceClients"
runat="server" OldValuesParameterFormatString="original_{0}"
SelectMethod="GetData"
TypeName="dsMiscDataTableAdapters.ClientsTableAdapter">
</asp:ObjectDataSource>


Now when the page come's up the first time I have only Clients
available (ok) . When i select a client for the first time only the
corresponding contacts are available in the contactDropdownList. When i
then select a different client i get that client's contact plus all
contacts i had before ??? What is happening here ?

Any help is welcome
Thanks
mateo
 
M

mateo

Ok I found the problem .

I was using AppendDataBoundItems on the second list, i just turned it
off and manually add a default value ("Select contact...")
in the event DropDownListContact_DataBound. This way i get only contact
associated with the right client.

It work's just fine.
Wonder if there's another way of doing this?
mateo
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,969
Messages
2,570,161
Members
46,708
Latest member
SherleneF1

Latest Threads

Top