I have a dropdownbox object:
<asp:DropDownLi st ID="ddlQuestion Type" runat="server">
<asp:ListItem Value="MS" Text="Multiple Single" />
<asp:ListItem Value="MM" Text="Multiple Multiple" />
<asp:ListItem Value="TF" Text="True/False" />
</asp:DropDownLis t>
The values and text are static. I am reading from a table:
Select QuestionType from myTable where id = 10
and QuestionType will either be "MS", "MM" or "TF".
How do I bind the data to this object?
With a Label it would be something like:
<asp:label id="Question" Text='<%# DataBinder.Eval (Container.Data Item,
"QuestionUnique ") %>' runat="server" />
Thanks,
Tom. 10 11251
Databinding from a SQL table is easy, you should be able to find many
examples out there.
You need to know more about this database you are querying though.
1.) Is it a MS SQL server or is it another type?
2.) Do you have to login to the server, or does it accept inherited
credentials?
3.) Do you have the database name you are connecting to?
"Chad Devine" <su*****@gmail. com> wrote in message
news:11******** *************@z 14g2000cwz.goog legroups.com... Databinding from a SQL table is easy, you should be able to find many examples out there.
You need to know more about this database you are querying though.
1.) Is it a MS SQL server or is it another type? 2.) Do you have to login to the server, or does it accept inherited credentials? 3.) Do you have the database name you are connecting to?
Actuall, no.
How I get the data is not the issue here.
I can get the data fine. It will always be either MM, MS or TF. I also
have no problem binding to a textbox, label, datagrid etc.
<%# DataBinder.Eval (Container.Data Item, "QuestionUnique ") %>
I want to do the same type of thing here where my selected item will display
based on the data returned.
Somehow, I need to do something like:
questionType.Se lectedItem.valu e = <%# DataBinder.Eval (Container.Data Item,
"QuestionTy pe") %>
So that the value will show correctly in the dropdownbox.
Thanks,
Tom
Oh so you want the dropdownlist to change the currently selected item
to the one that's in the table? I have tried doing that in the past but
haven't had any luck, I'm only intermediate in skill with asp.net so
hopefully someone else can provide a solution for you.
It may require you to go as far as using a custom control for what you
are trying to do.
"Chad Devine" <su*****@gmail. com> wrote in message
news:11******** **************@ c13g2000cwb.goo glegroups.com.. . Oh so you want the dropdownlist to change the currently selected item to the one that's in the table? I have tried doing that in the past but haven't had any luck, I'm only intermediate in skill with asp.net so hopefully someone else can provide a solution for you.
It may require you to go as far as using a custom control for what you are trying to do.
I hope not.
I assume that other people must do this. The problem with other examples,
is that they assume you want to populate the list with the results from your
table. But if you are looking at data that was already input and want to
allow the user to make a change to that data later, you would set the
dropdown to the data they had already chosen and allow them to choose
something else from the dropdown.
Thanks,
Tom.
Yeah, I completely agree with you and what you say makes sense.
Many suggest that doing a
If not ispostback then
DropDownList.Da taBind()
End If
So that the databind doesn't happen unless the person refreshes the
page, that way it keeps whatever the user selected, however in the case
of a table, when the user hits submit it refreshes the whole page so
that method doesn't work in this case. I really wish I could help you
in this, but I can't seem to find a property of the dropdownlist that
allows you to change the current selected item. You only seem to get
that chance right in the beginning when you define what options and
values to go into the list.
I just figured out your answer... I did it for myself, but with
autopostback it presents a little problem, when calling it in the
Page_Load sub because it won't let you change the current selected
item, as it keeps trying to select the previous one posted for some
reason.
Anyway, I put it in the sub Page_PreRender and it worked just fine.
Here's the code:
Sub Page_PreRender
dropListOptions .SelectedValue = intPageNumber
End Sub
<asp:DropDownLi st
ID="dropListOpt ions"
AutoPostBack="T rue"
OnSelectedIndex Changed="dropLi stOptions_Selec tedIndexChanged "
font-size="10"
Runat="Server" >
<asp:ListItem id="Default" Text="Default" Value="25" />
<asp:ListItem Text="50" Value="50" />
<asp:ListItem Text="75" Value="75" />
<asp:ListItem Text="100" Value="100" />
<asp:ListItem Text="150" Value="150" />
<asp:ListItem Text="200" Value="200" />
</asp:DropDownLis t>
Hope this helps!
Another update, I found that only works for Value properties, so if
your databinding this, this would be a problem... and then we're back
to square one.
Ignore the above post, I made an error in my code because I was writing
it too fast.
Anyway, this solution works fine, and it's all in sub code which I
think is better... that way you don't have to scroll between variables
in your html and your subs, it's all in one place. Again, I hope this
helps. This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: rmorvay |
last post by:
I am trying to dynamically build a dropdownlist and bind it to a cell in a
grid. I tried to utilize the following code but I am stuck at the point
where I bind the dropdownlist to the grid cell. I get the following message
for this code but I suspect that the "
UltraWebGrid1.Rows.Cells.Value = ddlGeography;" is not how you
bind the dropdownlist control to the grid. ERROR: "The type
'System.Web.UI.WebControls.DropDownList' must be...
|
by: theo |
last post by:
Program flow...load file,then extract the xml text tags from the
file,then the number of
Xml tags retrieved from the file determines the number of dropdownlist
controls
instanciated in the placeholder,the user selects the required tags from
the
dropdownlists (if 5 Xml tags,then 5 dropdownlists each containing 5 xml
tags) and now
the btnSave button is selected which extracts the user selection form
the dropdownlists.
|
by: Julia Hu |
last post by:
Hi,
I have a datagrid, and in different rows I need to
programmatically bind different type of controls and load
data into these controls. For example,in the first row I
need to bind data into a textbox, and in the second row I
need to bind data into a dropdownlist...It all depends on
the data I select from the database.
I cannot use TemplateColumn because it has to be the same
type of control for one column.
|
by: Sacha Korell |
last post by:
I'm trying to load a drop-down list with all DropDownList control names from
another page.
How would I be able to find those DropDownList controls? The FindControl
method will only find a certain control by id, but I want to find all
controls of a certain type (DropDownList in this case).
Is there an easier way than to get a control count of the page, loop through
all controls on that page, examine their type and, if they're a...
|
by: Assimalyst |
last post by:
Hi,
I'm attempting to use a data reader to load data from a single table,
tblCountry, with two columns, countryNo (the Key) and countryName, into
a DropDownList box. Here's the code:
protected System.Data.SqlClient.SqlConnection conn;
protected System.Data.SqlClient.SqlDataReader drCountry;
| |
by: pradeepthakar |
last post by:
i want to display "select" in my dropdownlist control on my page . this dropdownlist is supposed to retrieve values from database on selection of items in the dropdownlist . in this process, the (static html text) "select" must not interfere.
|
by: =?Utf-8?B?VmljdG9yaW91czE=?= |
last post by:
When the editcommand is execured for my datagrid the dropdown list appears
for the bound item status. However, the item selected by default does not
match the unedited data. How do I make the dropdownlist selected item match
the correspond to the original data. HTML for dropdownlist below
<EditItemTemplate>
<asp:DropDownList ID="DropDownListStatus" runat="server" DataValueField
= '<%# DataBinder.Eval(Container, "DataItem.screen_status")...
|
by: bogdan |
last post by:
Hi,
I'd like to use a dropdownlist in a formview to map numeric values to
'user-friendly' descriptions. The dropdownlist items' values need to be
bound to a column in a db table. For example, users might see "Type1",
"Type2", and "Type3" but corresponding values stored in db are 1, 2, and 3.
Seems like a very common scenario. Could anyone please let me know what the
best practice is in this case? Should I create a custom data source...
|
by: nzkks |
last post by:
Hi I am using these: ASP.Net 2.0, VB.Net, Visual Studio 2005, SQL Server 2005, Formview controls
In a ASP.Net form I have 20 textboxes and 20 dropdownlists(ddl). All ddl(s) are databound and get the data from a single objectdatasource. All textboxes and ddl(s) support null values. Textboxes are for entering numbers and ddl(s) are for selecting the unit (mm, cm, in, m3, oz, qt like these.).
I am using the below code to achieve two...
|
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...
|
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,...
| |
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...
|
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...
|
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
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 then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
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...
| |
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
| |