473,398 Members | 2,113 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,398 software developers and data experts.

Passing a Parameter to DropDownList DataSource Call within GridView Row

I am able to populate a DropDownList control within multiple rows of a
GridView with the following code:

`````````````````````````````````````````````````` ````
<asp:GridView id="gvGridView" runat="server"
AutoGenerateColumns="False" DataKeyNames="idRecordID">
<Columns>
<asp:TemplateField>
<ItemTemplate>

<asp:DropDownList
id="ddlDropDownList1"
runat="server"
DataTextField="strName"
DataValueField="intValue"
DataSource='<%# LoadDDL() %>'
SelectedValue='<%# Bind("intRowValue") %>' />

</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="intRowValue" HeaderText="RowValue" />
</Columns>
</asp:GridView>

CodeBehind:

Function LoadDDL() As DataSet

Dim objConn As New SqlConnection()
Dim objDataSet As New DataSet()
Dim strSQL As String
objConn = New
SqlConnection(ConfigurationManager.ConnectionStrin gs("connDatabaseConnection").ConnectionString)

strSQL = "SELECT strName, intValue FROM tblTable;"

Dim objDataAdapter As New SqlDataAdapter(strSQL, objConn)
objDataAdapter.Fill(objDataSet, "tblTable")
Return objDataSet

End Function

``````````````````````````````````````````````

But now I want to populate the dropdownlist dynamically with a variable
that comes from the record of the Gridivew row itself, like this:

`````````````````````````````````````````

<asp:GridView id="gvGridView" runat="server"
AutoGenerateColumns="False" DataKeyNames="idRecordID">
<Columns>
<asp:TemplateField>
<ItemTemplate>

<asp:DropDownList
id="ddlDropDownList1"
runat="server"
DataTextField="strName"
DataValueField="intValue"
DataSource='<%# LoadDDL(idRecordID) %>'
SelectedValue='<%# Bind("intRowValue") %>' />

</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="intRowValue" HeaderText="RowValue" />
</Columns>
</asp:GridView>

CodeBehind:

Function LoadDDL(ByVal idRecordID As Integer) As DataSet

Dim objConn As New SqlConnection()
Dim objDataSet As New DataSet()
Dim strSQL As String
objConn = New
SqlConnection(ConfigurationManager.ConnectionStrin gs("connDatabaseConnection").ConnectionString)

strSQL = "SELECT strName, intValue FROM tblTable WHERE intValue = "
& idRecordID & ";"

Dim objDataAdapter As New SqlDataAdapter(strSQL, objConn)
objDataAdapter.Fill(objDataSet, "tblTable")
Return objDataSet

End Function

`````````````````````````````````````````````

This second version doesn't work. The problem is, I can't figure out
how to pass a value from the row (or DataKeyNames) into the DataSet
call in the DropDownList Datasource property. Is this possible and does
anyone know the syntax for passing a parameter this way?

Jul 12 '06 #1
0 2100

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

Similar topics

2
by: COHENMARVIN | last post by:
I'm leafing through a big book on asp.net, and I don't see any way to the following: 1. bind values and text to a dropdown 2. Also make the first line of the dropdown say something different. For...
13
by: anonymike | last post by:
Hello, I started working with the ObjectDataSource today. I have the select, and have been working on getting the update method to work. Here is the asp code for my Data source: ...
5
by: glenn | last post by:
Hi folks, The problem I have is that a query string works if hard-coded but if I pass a variable to it, it does not work as shown here. This works: querystring="SELECT * FROM USERS WHERE...
0
by: den 2005 | last post by:
Hi everybody, I created a Gridview with a TemplateField and there is Label control in ItemTemplate and a DropdownList control in EditItemTemplate, I was to displayed them ok when I click the...
2
by: sree reddy | last post by:
..cs using System; using System.Data; using System.Configuration; using System.Collections; using System.Web; using System.Web.Security; using System.Web.UI; using System.Web.UI.WebControls;
1
by: Anilsg | last post by:
Hi all, I have the DropDownList in the FormView,inside InsertTemplateField The data is binded in run time to it in codebehind page,FOr the First time the page is loaded the DropdownList is...
0
by: Anilsg | last post by:
Hi all, I have the DropDownList in the FormView,inside InsertTemplateField The data is binded in run time to it in codebehind page,FOr the First time the page is loaded the DropdownList...
0
by: Fabrizio | last post by:
Hi all. I have a field in a gridview as templatefield which is a label in view mode and a dropdownlist in edit mode with his datasource. This gridview is inserted as templatefield in another...
0
by: Moneypenny | last post by:
Hi there, I have a Gridview control which has a dropdownlist in every row. The dropdowns are populated dynamically from a database (so the content is different in each row. There is also a select...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
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
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
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
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...
0
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 project—planning, coding, testing,...

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.