473,513 Members | 2,561 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

GridView Binding?

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

Feb 28 '06 #1
3 6984
http://www.webswapp.com/codesamples/...s/default.aspx
--
HTH,
Phillip Williams
http://www.societopia.net
http://www.webswapp.com
"mateo" wrote:
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

Feb 28 '06 #2
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.ContactsTableAda pter"
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.ClientsTableAdap ter">
</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

Mar 1 '06 #3
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

Mar 1 '06 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
18520
by: sck10 | last post by:
Hello, I have a GridView that is using the following to connect to a SQL Server 2000 stored procedure: <asp:SqlDataSource ID="dsWebDocList" SelectCommand="sp_web_WebDocument"...
1
2004
by: Smash | last post by:
I have problem binding gridview.... At first i didn't want to bind gridview at first page load...so in my objectdatasource_selecting event i wrote this: If Not Page.IsPostBack Then e.Cancel =...
5
11199
by: Amit | last post by:
Hello, I have a simple search screen, with two drop-downs and a text box. There's also a GridView control that is using a SqlDataSource control to show the matching results. The SqlDataSource uses...
1
14299
by: CorporateCoder | last post by:
Hi, I am trying to bind the selected value of a databound dropdown box in a databound gridview control to the value being displayed in the template column the dropdown box has been added to. ...
8
8517
by: AG | last post by:
ASP.NET 2.0, VS 2005 I have a gridview with paging enabled, bound to an objectdatasource. Both were dropped on to the page and configured via the wizards. Basically working as expected. The...
4
2592
by: Mike | last post by:
I'm having trouble getting a gridview to bind. I probably missing something completely obvious and would appreciate any help on offer. I'm passing parameters via querystring, and have created a...
2
13161
by: antonyliu2002 | last post by:
I've been googling for some time, and could not find the solution to this problem. I am testing the paging feature of gridview. I have a very simple web form on which the user can select a few...
8
7708
by: gerry | last post by:
The PagerSettings.Visible property is not being handled properly by the GridView control. The value assigned to this property is not applied until after a postback. Simplest test : .aspx...
0
3538
by: ER | last post by:
Hi Guys Started having a play with WPF and need some direction with a grid. I am trying to build a list of products in a grid view with combox boxes as column headers that allow filtering and...
1
2489
by: =?Utf-8?B?U2hhdw==?= | last post by:
I have a small GridView about max 10 rows and few columns. The columns are simple just a checkbox and a textbox and a bound name. The users don’t want to click “edit” button to edit and...
0
7158
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7380
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7535
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
7098
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
5683
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development projectplanning, coding, testing,...
0
4745
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3232
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3221
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
798
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.