473,725 Members | 1,811 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

use GridView boundfield value for DropDownList select where clause

I have a dropdownlist in a GridView ItemTemplate. I need to bind the ddl to
an SqlDataSource, then have a value from a boundfield in the row be passed as
the keyfield for select where clause. Im trying to load the ddl with a list
of dates from another table keyed on GridView row field that only apply to
this row.

Any suggestions would be appreciated.

Apr 3 '06 #1
6 8268
I have done it in this demo using an ObjectDataSourc e; where one of the
properties in the databound business class is a collection of the list items
specific to each row.

http://www.webswapp.com/codesamples/...w/default.aspx

If you want to do it using SQLDataSource, you will have to either intervene
during the RowUpdated event to trigger another SQL query that returns a list
of item that you bind to the dropdownlist or you can add the field that
determines the listitems selection process in the GridView. DataKeyNames then
set a SqlDataSource within the ItemTemplate with a parameter referencing that
datakey, e.g.

<asp:ControlPar ameter ControlID="Grid View1" Name="CategoryI D"
PropertyName="S electedDataKey. Values[1]" Type="Int32" />

--
HTH,
Phillip Williams
http://www.societopia.net
http://www.webswapp.com
"Dabbler" wrote:
I have a dropdownlist in a GridView ItemTemplate. I need to bind the ddl to
an SqlDataSource, then have a value from a boundfield in the row be passed as
the keyfield for select where clause. Im trying to load the ddl with a list
of dates from another table keyed on GridView row field that only apply to
this row.

Any suggestions would be appreciated.

Apr 3 '06 #2
Thanks Phillip, I studied the example with ObjectDataSourc e but was hoping I
could implement this just using SqlDataSource.

I tried your selectedkeys.va lues[1] but still don't get any data in the ddl.
Here's my code:
<asp:GridView ID="Registrants GridView" runat="server"
DataSourceID="R egistrantsSqlDa taSource"
AllowPaging="Tr ue" AllowSorting="T rue" AutoGenerateCol umns="False"
CssClass="waGri dView"
DataKeyNames="R egistrantId" ... >
<Columns>
<asp:BoundFie ld DataField="Regi strantId" HeaderText="Id"
InsertVisible=" False" ReadOnly="True" SortExpression= "Registrant Id" />
<asp:TemplateFi eld>
<ItemTemplate >
<asp:DropDownLi st ID="RideDates" runat="server"
DataSourceId="R ideDatesSqlData Source">
</asp:DropDownLis t>
<asp:SqlDataSou rce ID="RideDatesSq lDataSource" runat="server"
ConnectionStrin g="<%$ ConnectionStrin gs:myDB %>"
ProviderName="S ystem.Data.SqlC lient"
SelectCommand=" GetRegRideDates " SelectCommandTy pe="StoredProce dure">
<SelectParamete rs>
<asp:ControlPar ameter ControlID="Regi strantsGridView "
Name="Registran tId"
PropertyName="S electedDataKey. Values[1]" Type="Int32" />
</SelectParameter s>
</asp:SqlDataSour ce>
</ItemTemplate>
</TemplateField>

"Phillip Williams" wrote:
I have done it in this demo using an ObjectDataSourc e; where one of the
properties in the databound business class is a collection of the list items
specific to each row.

http://www.webswapp.com/codesamples/...w/default.aspx

If you want to do it using SQLDataSource, you will have to either intervene
during the RowUpdated event to trigger another SQL query that returns a list
of item that you bind to the dropdownlist or you can add the field that
determines the listitems selection process in the GridView. DataKeyNames then
set a SqlDataSource within the ItemTemplate with a parameter referencing that
datakey, e.g.

<asp:ControlPar ameter ControlID="Grid View1" Name="CategoryI D"
PropertyName="S electedDataKey. Values[1]" Type="Int32" />

--
HTH,
Phillip Williams
http://www.societopia.net
http://www.webswapp.com
"Dabbler" wrote:
I have a dropdownlist in a GridView ItemTemplate. I need to bind the ddl to
an SqlDataSource, then have a value from a boundfield in the row be passed as
the keyfield for select where clause. Im trying to load the ddl with a list
of dates from another table keyed on GridView row field that only apply to
this row.

Any suggestions would be appreciated.

Apr 3 '06 #3
You are right. I just tried it and it does not work. I forgot that while the
GridViewRow is being created there are no selected rows yet to have values in
the SelectedDataKey .

However I tried this modification and it worked:

<asp:TemplateFi eld>
<ItemTemplate >
<asp:Label id="lblRegistra ntId" runat="Server"
Text='<%#Bind(" RegistrantId")% ' cssClass="hidde n"></asp:Label>
<asp:DropDownLi st ID="RideDates" runat="server"
DataSourceId="R ideDatesSqlData Source">
</asp:DropDownLis t>
<asp:SqlDataSou rce ID="RideDatesSq lDataSource" runat="server"
ConnectionStrin g="<%$ ConnectionStrin gs:myDB %>"
ProviderName="S ystem.Data.SqlC lient"
SelectCommand=" GetRegRideDates " SelectCommandTy pe="StoredProce dure">
<SelectParamete rs>
<asp:ControlPar ameter ControlID="lblR egistrantId"
Name="Registran tId"
Type="Int32" />
</SelectParameter s>
</asp:SqlDataSour ce>
</ItemTemplate>
</TemplateField>
where the style class definition would be:
..hidde {display:none;}
--
HTH,
Phillip Williams
http://www.societopia.net
http://www.webswapp.com
"Dabbler" wrote:
Thanks Phillip, I studied the example with ObjectDataSourc e but was hoping I
could implement this just using SqlDataSource.

I tried your selectedkeys.va lues[1] but still don't get any data in the ddl.
Here's my code:
<asp:GridView ID="Registrants GridView" runat="server"
DataSourceID="R egistrantsSqlDa taSource"
AllowPaging="Tr ue" AllowSorting="T rue" AutoGenerateCol umns="False"
CssClass="waGri dView"
DataKeyNames="R egistrantId" ... >
<Columns>
<asp:BoundFie ld DataField="Regi strantId" HeaderText="Id"
InsertVisible=" False" ReadOnly="True" SortExpression= "Registrant Id" />
<asp:TemplateFi eld>
<ItemTemplate >
<asp:DropDownLi st ID="RideDates" runat="server"
DataSourceId="R ideDatesSqlData Source">
</asp:DropDownLis t>
<asp:SqlDataSou rce ID="RideDatesSq lDataSource" runat="server"
ConnectionStrin g="<%$ ConnectionStrin gs:myDB %>"
ProviderName="S ystem.Data.SqlC lient"
SelectCommand=" GetRegRideDates " SelectCommandTy pe="StoredProce dure">
<SelectParamete rs>
<asp:ControlPar ameter ControlID="Regi strantsGridView "
Name="Registran tId"
PropertyName="S electedDataKey. Values[1]" Type="Int32" />
</SelectParameter s>
</asp:SqlDataSour ce>
</ItemTemplate>
</TemplateField>

"Phillip Williams" wrote:
I have done it in this demo using an ObjectDataSourc e; where one of the
properties in the databound business class is a collection of the list items
specific to each row.

http://www.webswapp.com/codesamples/...w/default.aspx

If you want to do it using SQLDataSource, you will have to either intervene
during the RowUpdated event to trigger another SQL query that returns a list
of item that you bind to the dropdownlist or you can add the field that
determines the listitems selection process in the GridView. DataKeyNames then
set a SqlDataSource within the ItemTemplate with a parameter referencing that
datakey, e.g.

<asp:ControlPar ameter ControlID="Grid View1" Name="CategoryI D"
PropertyName="S electedDataKey. Values[1]" Type="Int32" />

--
HTH,
Phillip Williams
http://www.societopia.net
http://www.webswapp.com
"Dabbler" wrote:
I have a dropdownlist in a GridView ItemTemplate. I need to bind the ddl to
an SqlDataSource, then have a value from a boundfield in the row be passed as
the keyfield for select where clause. Im trying to load the ddl with a list
of dates from another table keyed on GridView row field that only apply to
this row.

Any suggestions would be appreciated.

Apr 3 '06 #4

Ok, I got it to work with your suggestion to load the ddl in code instead of
using SqlDataSource. I used RowDataBound event, so I could pull the key value
from a cell using e.Row.Cells[1].Text. I think the RowUpdatedEvent doesn't
trigger while the Gridview is loading, which is what i needed to load the
initial ddl values.

Thanks for the tip!

"Phillip Williams" wrote:
I have done it in this demo using an ObjectDataSourc e; where one of the
properties in the databound business class is a collection of the list items
specific to each row.

http://www.webswapp.com/codesamples/...w/default.aspx

If you want to do it using SQLDataSource, you will have to either intervene
during the RowUpdated event to trigger another SQL query that returns a list
of item that you bind to the dropdownlist or you can add the field that
determines the listitems selection process in the GridView. DataKeyNames then
set a SqlDataSource within the ItemTemplate with a parameter referencing that
datakey, e.g.

<asp:ControlPar ameter ControlID="Grid View1" Name="CategoryI D"
PropertyName="S electedDataKey. Values[1]" Type="Int32" />

--
HTH,
Phillip Williams
http://www.societopia.net
http://www.webswapp.com
"Dabbler" wrote:
I have a dropdownlist in a GridView ItemTemplate. I need to bind the ddl to
an SqlDataSource, then have a value from a boundfield in the row be passed as
the keyfield for select where clause. Im trying to load the ddl with a list
of dates from another table keyed on GridView row field that only apply to
this row.

Any suggestions would be appreciated.

Apr 3 '06 #5
Interesting that this worked for you. The only difference between this and my
last failed attempt using SqlDataSource is that you are using a label control
in an item template, whereas I was using the RegistrantId in a visible
BoundField. I'm guessing that the BoundFields have mangeled Id names instead
of the original Id names.

"Phillip Williams" wrote:
You are right. I just tried it and it does not work. I forgot that while the
GridViewRow is being created there are no selected rows yet to have values in
the SelectedDataKey .

However I tried this modification and it worked:

<asp:TemplateFi eld>
<ItemTemplate >
<asp:Label id="lblRegistra ntId" runat="Server"
Text='<%#Bind(" RegistrantId")% ' cssClass="hidde n"></asp:Label>
<asp:DropDownLi st ID="RideDates" runat="server"
DataSourceId="R ideDatesSqlData Source">
</asp:DropDownLis t>
<asp:SqlDataSou rce ID="RideDatesSq lDataSource" runat="server"
ConnectionStrin g="<%$ ConnectionStrin gs:myDB %>"
ProviderName="S ystem.Data.SqlC lient"
SelectCommand=" GetRegRideDates " SelectCommandTy pe="StoredProce dure">
<SelectParamete rs>
<asp:ControlPar ameter ControlID="lblR egistrantId"
Name="Registran tId"
Type="Int32" />
</SelectParameter s>
</asp:SqlDataSour ce>
</ItemTemplate>
</TemplateField>
where the style class definition would be:
.hidde {display:none;}
--
HTH,
Phillip Williams
http://www.societopia.net
http://www.webswapp.com
"Dabbler" wrote:
Thanks Phillip, I studied the example with ObjectDataSourc e but was hoping I
could implement this just using SqlDataSource.

I tried your selectedkeys.va lues[1] but still don't get any data in the ddl.
Here's my code:
<asp:GridView ID="Registrants GridView" runat="server"
DataSourceID="R egistrantsSqlDa taSource"
AllowPaging="Tr ue" AllowSorting="T rue" AutoGenerateCol umns="False"
CssClass="waGri dView"
DataKeyNames="R egistrantId" ... >
<Columns>
<asp:BoundFie ld DataField="Regi strantId" HeaderText="Id"
InsertVisible=" False" ReadOnly="True" SortExpression= "Registrant Id" />
<asp:TemplateFi eld>
<ItemTemplate >
<asp:DropDownLi st ID="RideDates" runat="server"
DataSourceId="R ideDatesSqlData Source">
</asp:DropDownLis t>
<asp:SqlDataSou rce ID="RideDatesSq lDataSource" runat="server"
ConnectionStrin g="<%$ ConnectionStrin gs:myDB %>"
ProviderName="S ystem.Data.SqlC lient"
SelectCommand=" GetRegRideDates " SelectCommandTy pe="StoredProce dure">
<SelectParamete rs>
<asp:ControlPar ameter ControlID="Regi strantsGridView "
Name="Registran tId"
PropertyName="S electedDataKey. Values[1]" Type="Int32" />
</SelectParameter s>
</asp:SqlDataSour ce>
</ItemTemplate>
</TemplateField>

"Phillip Williams" wrote:
I have done it in this demo using an ObjectDataSourc e; where one of the
properties in the databound business class is a collection of the list items
specific to each row.

http://www.webswapp.com/codesamples/...w/default.aspx

If you want to do it using SQLDataSource, you will have to either intervene
during the RowUpdated event to trigger another SQL query that returns a list
of item that you bind to the dropdownlist or you can add the field that
determines the listitems selection process in the GridView. DataKeyNames then
set a SqlDataSource within the ItemTemplate with a parameter referencing that
datakey, e.g.

<asp:ControlPar ameter ControlID="Grid View1" Name="CategoryI D"
PropertyName="S electedDataKey. Values[1]" Type="Int32" />

--
HTH,
Phillip Williams
http://www.societopia.net
http://www.webswapp.com
"Dabbler" wrote:

> I have a dropdownlist in a GridView ItemTemplate. I need to bind the ddl to
> an SqlDataSource, then have a value from a boundfield in the row be passed as
> the keyfield for select where clause. Im trying to load the ddl with a list
> of dates from another table keyed on GridView row field that only apply to
> this row.
>
> Any suggestions would be appreciated.
>

Apr 3 '06 #6
Yes, DataBound fields do not have an ID property. If you right-mouse click
on the browser to view the rendered HTML you will see that the bound field
rendered the content of your the databound field within a TableCell.
Therefore you could not refer to it. However by specifying a templateField
in which I added a server control (the label) containing the RegistrantId, I
managed to refer to that control by its ID.
--
HTH,
Phillip Williams
http://www.societopia.net
http://www.webswapp.com
"Dabbler" wrote:
Interesting that this worked for you. The only difference between this and my
last failed attempt using SqlDataSource is that you are using a label control
in an item template, whereas I was using the RegistrantId in a visible
BoundField. I'm guessing that the BoundFields have mangeled Id names instead
of the original Id names.

"Phillip Williams" wrote:
You are right. I just tried it and it does not work. I forgot that while the
GridViewRow is being created there are no selected rows yet to have values in
the SelectedDataKey .

However I tried this modification and it worked:

<asp:TemplateFi eld>
<ItemTemplate >
<asp:Label id="lblRegistra ntId" runat="Server"
Text='<%#Bind(" RegistrantId")% ' cssClass="hidde n"></asp:Label>
<asp:DropDownLi st ID="RideDates" runat="server"
DataSourceId="R ideDatesSqlData Source">
</asp:DropDownLis t>
<asp:SqlDataSou rce ID="RideDatesSq lDataSource" runat="server"
ConnectionStrin g="<%$ ConnectionStrin gs:myDB %>"
ProviderName="S ystem.Data.SqlC lient"
SelectCommand=" GetRegRideDates " SelectCommandTy pe="StoredProce dure">
<SelectParamete rs>
<asp:ControlPar ameter ControlID="lblR egistrantId"
Name="Registran tId"
Type="Int32" />
</SelectParameter s>
</asp:SqlDataSour ce>
</ItemTemplate>
</TemplateField>
where the style class definition would be:
.hidde {display:none;}
--
HTH,
Phillip Williams
http://www.societopia.net
http://www.webswapp.com
"Dabbler" wrote:
Thanks Phillip, I studied the example with ObjectDataSourc e but was hoping I
could implement this just using SqlDataSource.

I tried your selectedkeys.va lues[1] but still don't get any data in the ddl.
Here's my code:
<asp:GridView ID="Registrants GridView" runat="server"
DataSourceID="R egistrantsSqlDa taSource"
AllowPaging="Tr ue" AllowSorting="T rue" AutoGenerateCol umns="False"
CssClass="waGri dView"
DataKeyNames="R egistrantId" ... >
<Columns>
<asp:BoundFie ld DataField="Regi strantId" HeaderText="Id"
InsertVisible=" False" ReadOnly="True" SortExpression= "Registrant Id" />
<asp:TemplateFi eld>
<ItemTemplate >
<asp:DropDownLi st ID="RideDates" runat="server"
DataSourceId="R ideDatesSqlData Source">
</asp:DropDownLis t>
<asp:SqlDataSou rce ID="RideDatesSq lDataSource" runat="server"
ConnectionStrin g="<%$ ConnectionStrin gs:myDB %>"
ProviderName="S ystem.Data.SqlC lient"
SelectCommand=" GetRegRideDates " SelectCommandTy pe="StoredProce dure">
<SelectParamete rs>
<asp:ControlPar ameter ControlID="Regi strantsGridView "
Name="Registran tId"
PropertyName="S electedDataKey. Values[1]" Type="Int32" />
</SelectParameter s>
</asp:SqlDataSour ce>
</ItemTemplate>
</TemplateField>

"Phillip Williams" wrote:

> I have done it in this demo using an ObjectDataSourc e; where one of the
> properties in the databound business class is a collection of the list items
> specific to each row.
>
> http://www.webswapp.com/codesamples/...w/default.aspx
>
> If you want to do it using SQLDataSource, you will have to either intervene
> during the RowUpdated event to trigger another SQL query that returns a list
> of item that you bind to the dropdownlist or you can add the field that
> determines the listitems selection process in the GridView. DataKeyNames then
> set a SqlDataSource within the ItemTemplate with a parameter referencing that
> datakey, e.g.
>
> <asp:ControlPar ameter ControlID="Grid View1" Name="CategoryI D"
> PropertyName="S electedDataKey. Values[1]" Type="Int32" />
>
> --
> HTH,
> Phillip Williams
> http://www.societopia.net
> http://www.webswapp.com
>
>
> "Dabbler" wrote:
>
> > I have a dropdownlist in a GridView ItemTemplate. I need to bind the ddl to
> > an SqlDataSource, then have a value from a boundfield in the row be passed as
> > the keyfield for select where clause. Im trying to load the ddl with a list
> > of dates from another table keyed on GridView row field that only apply to
> > this row.
> >
> > Any suggestions would be appreciated.
> >

Apr 3 '06 #7

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

Similar topics

5
11506
by: malcolm | last post by:
Example, suppose you have these 2 tables (NOTE: My example is totally different, but I'm simply trying to setup the a simpler version, so excuse the bad design; not the point here) CarsSold { CarsSoldID int (primary key) MonthID int DealershipID int NumberCarsSold int
1
4430
by: krian | last post by:
Hi, How can I change the styles of the DropDownList(Select box)..? and also I want to place an image in the place of DropDownButton of Select Box .. How can i done these in DHTML..?. I would like to know an example on Customizing DorpDownButton of the DropDownList or Select Box(Changing DropDownButton border,placing image as background to buttona and background colors..)
8
10318
by: Jean | last post by:
Hello all, I have the following data, that was queried and sorted to columns PROBLEM_ID and then by STATUSDATE (ascending): STATUS_ID STATUSDATE PROBLEM_ID --------- ---------- ---------- 10 12/04/2005 1234 40 15/05/2005 1234
2
1312
by: Lone Wolf | last post by:
We have a recordset with the following structure id (int), mls (varchar) What we need to do is within a single sql call we need to show all records where the mls = '' and all unique records where mls!='' In other words, there will be multiple records with duplicate mls entries. We do not want to show duplicate enties for where the mls has been set, only where the mls has not been set.
0
1297
by: R.A.M. | last post by:
Hello, Could you help me please to define GridView associated to DropDownList. My DropDownList "Publishers" should show publishers' names from SQL Server table Publishers. My GridView "BooksOnDotNET"should show books published by selected publisher. (Tables' definition below.) Here is part of .aspx: <asp:DropDownList ID="Publishers" runat="server"
2
1473
by: cephelo | last post by:
I have no problems outputting the attribute value when the node is in context, for example, @id when an <status> node is in context. However, I am having trouble outputting it in a <xsl:value-of /> element: <xsl:value-of select="procresults/settings@priority /> where it looks like
5
10154
by: No bother | last post by:
I am using 5.0.26-NT on Windows 2000. I have need to use a reference in the outer from clause in a subquery in the select clause. Consider the following example: Select (select b.baitID from b where b.entrydate curdate()) as wantedBaitIDs from bait_tbl b; My actual need is more complex than this as part of it is a rough cross tab. If I try to define the table in the alias, not only do I lose
5
7133
by: paragpdoke | last post by:
Hello Everyone. I'm new to XSL and couldn't get something to work. Sample XML excerpt: <root> <ObjectTemplate> <NodeType1></NodeType1> <NodeType2></NodeType2> </ObjectTemplate> <Object>
1
3697
by: loix | last post by:
I'm trying to Insert 300.000 rows (or thereabouts) into a table (via QMF) using the following Select clause: # Insert into table_name ( Select row1, row2, row..x from table_name2 Fetch first 300000 rows only); # The only message I get is that there's an error with the Fecth statement.
0
8872
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8747
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9392
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9246
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9091
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6694
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4505
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4773
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3211
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

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.