473,378 Members | 1,209 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,378 software developers and data experts.

set selected value declaratively to dropdownlist

Hi,
I just wonder if there is a way to set a selected item in dropdown list
which items are retreived from database without touching c# code ?

I mean, i have in gridview, in edit mode one dropdownlist which
selected value should be the same as a label text from normal view mode

<EditItemTemplate>
<asp:DropDownList ID="ddlGrdvFrequency" runat="server"
DataTextField="Frequency"
DataValueField="FrequencyId"
DataSourceID="SqlDataSourceMembershipFrequency" />

</EditItemTemplate>

I was looking for sth like SelectedIndex, but intellisense did not give
me any prompt for it. I use now C# code in databound event for gridview
to set this item selected, but ...is there a way of not using this ?
thanks for any prompts

Sep 23 '06 #1
3 6554
Hi,
You can set the selectedvalue property on the dropdownlist as follows
<EditItemTemplate>
<asp:DropDownList runat="server" ID="ddl"
DataSourceID="SqlDataSource2"
DataValueField="ProductID"
DataTextField="ProductName" SelectedValue='<%# Bind("ProductID")
%>'></asp:DropDownList>
</EditItemTemplate>

Regards,
Mohamed Mosalem

"podi" wrote:
Hi,
I just wonder if there is a way to set a selected item in dropdown list
which items are retreived from database without touching c# code ?

I mean, i have in gridview, in edit mode one dropdownlist which
selected value should be the same as a label text from normal view mode

<EditItemTemplate>
<asp:DropDownList ID="ddlGrdvFrequency" runat="server"
DataTextField="Frequency"
DataValueField="FrequencyId"
DataSourceID="SqlDataSourceMembershipFrequency" />

</EditItemTemplate>

I was looking for sth like SelectedIndex, but intellisense did not give
me any prompt for it. I use now C# code in databound event for gridview
to set this item selected, but ...is there a way of not using this ?
thanks for any prompts

Sep 23 '06 #2
hi podi,
unfortunately the SelectedIndex cannot be set declaratively, it is a compile
error. i'm just wondering how you could know in advance with a databound
list which one to select?
an alternative would be to sort the datasource so that the one you want to
select is the first record, then it will be selected by default when the
list is databound.

i think the databound event is the correct (and best) place to achieve your
task.
i hope this helps
tim

"podi" <lu************@gmail.comwrote in message
news:11**********************@d34g2000cwd.googlegr oups.com...
Hi,
I just wonder if there is a way to set a selected item in dropdown list
which items are retreived from database without touching c# code ?

I mean, i have in gridview, in edit mode one dropdownlist which
selected value should be the same as a label text from normal view mode

<EditItemTemplate>
<asp:DropDownList ID="ddlGrdvFrequency" runat="server"
DataTextField="Frequency"
DataValueField="FrequencyId"
DataSourceID="SqlDataSourceMembershipFrequency" />

</EditItemTemplate>

I was looking for sth like SelectedIndex, but intellisense did not give
me any prompt for it. I use now C# code in databound event for gridview
to set this item selected, but ...is there a way of not using this ?
thanks for any prompts

Sep 23 '06 #3
Thank you for responses, it helped

Tim_Mac wrote:
hi podi,
unfortunately the SelectedIndex cannot be set declaratively, it is a compile
error. i'm just wondering how you could know in advance with a databound
list which one to select?
an alternative would be to sort the datasource so that the one you want to
select is the first record, then it will be selected by default when the
list is databound.

i think the databound event is the correct (and best) place to achieve your
task.
i hope this helps
tim

"podi" <lu************@gmail.comwrote in message
news:11**********************@d34g2000cwd.googlegr oups.com...
Hi,
I just wonder if there is a way to set a selected item in dropdown list
which items are retreived from database without touching c# code ?

I mean, i have in gridview, in edit mode one dropdownlist which
selected value should be the same as a label text from normal view mode

<EditItemTemplate>
<asp:DropDownList ID="ddlGrdvFrequency" runat="server"
DataTextField="Frequency"
DataValueField="FrequencyId"
DataSourceID="SqlDataSourceMembershipFrequency" />

</EditItemTemplate>

I was looking for sth like SelectedIndex, but intellisense did not give
me any prompt for it. I use now C# code in databound event for gridview
to set this item selected, but ...is there a way of not using this ?
thanks for any prompts
Oct 3 '06 #4

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

Similar topics

6
by: Julius Fenata | last post by:
Dear all, I have created client-side scripting to trigger event onChange from code-behind, like this: DropDownList1.Attributes = "GenerateArticleID()"; At the script on Windows Form, I...
2
by: NH | last post by:
How can I set the selected item in a dropdownlist which is declared in the edititemtemlpate of a gridview? Which gridview event should I use, I cant seem to figure it out...
1
by: rajiv Joshi | last post by:
Hi all I m displaying locations from database in the dropdownlist box using C# .Its displaying all locations properly but when i select loacation from dropdown it is always displaying first item...
1
by: sdshah5 | last post by:
hi, i want to know how to pass selected value from dropdownlist of child page to a multiline textbox on the parent page. in my code it is giving me the "id" of the selected dropdown value in the...
2
by: munther | last post by:
hi there : i was created datagrid and it have three template colume, in the template colume dropdownlist the dropdownlist get data from data base . * the question i want return selected value...
1
by: iswar | last post by:
Hi friends.. Im trying to bind a value from dropdownlist placed in gird view to another cell. i want to update a database field with the selected value from dropdownlist and which must be bind to...
3
by: Andy B | last post by:
I have a dropDownList and a LinkButton. The LinkButton's text needs to reflect the selected item in the dropDownList. So, when Subscribe is selected in the dropDownList, the LinkButton's text needs...
1
by: Neerav shah | last post by:
How to retrieve selected value of dropdownlist filled from datasource in asp.net? Dim str1 As String = "SELECT UserName FROM Login WHERE Category = 'Property'" Dim cmd1 As New...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
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: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?

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.