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

Problem Binding Data to DROP DOWN LIST CONTROL

string connectionString1 = "server=(local); user=sa;password=sa;
database=sonic";

System.Data.SqlClient.SqlConnection dbConnection1 = new
System.Data.SqlClient.SqlConnection(connectionStri ng1);
System.Data.SqlClient.SqlCommand dbCommand1 = new
System.Data.SqlClient.SqlCommand();


string sql="Select * From Student_SDS Where SSN='" + Session["SSN"] +
"'";
dbCommand1 = new SqlCommand (sql, dbConnection1);
dbConnection1.Open();
SqlDataReader dr = dbCommand1.ExecuteReader();
dr.Read();

LName.Text = Convert.ToString(dr["LName"]);
FName.Text= Convert.ToString(dr["FName"]);
MName.Text= Convert.ToString(dr["MName"]);
LocalAddress.Text= Convert.ToString(dr["LocalAddress"]);
Lcity.Text=Convert.ToString(dr["Lcity"]);
Lzip.Text=Convert.ToString(dr["Lzip"]);
BirthDate.Text=Convert.ToString(dr["BirthDate"]);
SchoolName.Text=Convert.ToString(dr["SchoolName"]);
SchoolOrigin.Text=Convert.ToString(dr["SchoolOrigin"]);
AGraduationDate.Text=Convert.ToString(dr["AGraduationDate"]);
Lstate.DataSource=dr;
Lstate.DataTextField="Lstate";
Lstate.DataBind();
USCitizen.DataSource=dr;
USCitizen.DataTextField="USCitizen";
USCitizen.DataBind();
SClassification.DataSource=dr;
SClassification.DataTextField="SClassification";
SClassification.DataBind();
SchoolState.DataSource=dr;
SchoolState.DataTextField="SchoolState";
SchoolState.DataBind();
SDSApplied.DataSource=dr;
SDSApplied.DataTextField="SDSApplied";
SDSApplied.DataBind();
LoanApplied.DataSource=dr;
LoanApplied.DataSource="LoanApplied";
LoanApplied.DataBind();
NursProg.DataSource=dr;
NursProg.DataTextField="NursProg";
NursProg.DataBind();
ProgType.DataSource=dr;
ProgType.DataTextField="ProgType";
ProgType.DataBind();
AwardWilling.DataSource=dr;
AwardWilling.DataTextField="AwardWilling";
AwardWilling.DataBind();
StayType.DataSource=dr;
StayType.DataTextField="StayType";
StayType.DataBind();
ParentGrad.DataSource=dr;
ParentGrad.DataTextField="ParentGrad";
ParentGrad.DataBind();
FirstStudy.DataSource=dr;
FirstStudy.DataTextField="FirstStudy";
FirstStudy.DataBind();
EnrollmentType.DataSource=dr;
EnrollmentType.DataTextField="EnrollmentType";
EnrollmentType.DataBind();
EnrollmentTerm.DataSource=dr;
EnrollmentTerm.DataTextField="EnrollmentTerm";
EnrollmentTerm.DataBind();
HoldVisa.DataSource=dr;
HoldVisa.DataMember="HoldVisa";
HoldVisa.DataTextField="HoldVisa";
HoldVisa.DataBind();
dr.Close();
dbConnection1.Close();

Well Here this code was for when PAGE LOAD.

Well The desired data was being Binded to the TEXT BOXES but.... THE DROP
DOWN LIST BOXES arent displaying anything... I donot know what the error
is. I wish some one could help me solve this or point the Error Out.
Well and the --------- code of each Drop DOwn List Boxes Initially designed
as........
WELL BELOW IS THE ASP DROP DOWN LIST CODE..... WHEN INITIALLY DESIGNED THIS
FORM.

I JUST WANT TO KNOW WHY THE DATA IS NOT BEING DISPLAYED BY THE ... DROP
DOWN LIST BOXES.

PLEASE HELP ME OUT.
WELL ONE MORE THING IS THAT---- THE TEXT AND THE VALUE ARE THE SAME -----
FOR THE DROP DOWN LIST ITEMS.

LIKE FOR THE NAME --- ARKANSAS> the VALUE WAS ALSO SET TO ARKANSAS.

SO I donot know how to retrieve the data in the database and to bind to
these controls.
Initially when the user fills the data from the drop down lists is added
into the database and when he second time comes in for editing the data, I
wish to show him the items he chose, I was successful in Binding the data
to ... TEXTBOXES but not to these Drop Down List Boxes.

SOME ONE PLEASE HELP ME OUT.
THANKS AND REGARDS>
WAITING FOR AN EARLY RESPONSE>

viggi.

<asp:dropdownlist id="SchoolState" style="Z-INDEX: 159; LEFT: 504px;
POSITION: absolute; TOP: 536px"
tabIndex="15" runat="server" BackColor="Gold" Width="120px">
<asp:ListItem Selected="True"></asp:ListItem>
<asp:ListItem Value="Alabama">Alabama</asp:ListItem>
<asp:ListItem Value="Alaska ">Alaska </asp:ListItem>
<asp:ListItem Value="Arizona ">Arizona </asp:ListItem>
<asp:ListItem Value="Arkansas ">Arkansas </asp:ListItem>
<asp:ListItem Value="California ">California </asp:ListItem>
<asp:ListItem Value="Colorado ">Colorado </asp:ListItem>
<asp:ListItem Value=" Connecticut "> Connecticut </asp:ListItem>
<asp:ListItem Value="Delaware ">Delaware </asp:ListItem>
<asp:ListItem Value="Florida ">Florida </asp:ListItem>
<asp:ListItem Value="Georgia ">Georgia </asp:ListItem>
<asp:ListItem Value="Hawaii ">Hawaii </asp:ListItem>
<asp:ListItem Value="Idaho ">Idaho </asp:ListItem>
<asp:ListItem Value="Illinois ">Illinois </asp:ListItem>
<asp:ListItem Value="Indiana ">Indiana </asp:ListItem>
<asp:ListItem Value="Iowa ">Iowa </asp:ListItem>
<asp:ListItem Value="Kansas ">Kansas </asp:ListItem>
<asp:ListItem Value="Kentucky ">Kentucky </asp:ListItem>
<asp:ListItem Value="Louisiana">Louisiana</asp:ListItem>
<asp:ListItem Value="Maine ">Maine </asp:ListItem>
<asp:ListItem Value="Maryland ">Maryland </asp:ListItem>
<asp:ListItem Value="Massachusetts ">Massachusetts </asp:ListItem>
<asp:ListItem Value="Michigan ">Michigan </asp:ListItem>
<asp:ListItem Value="Minnesota ">Minnesota </asp:ListItem>
<asp:ListItem Value="Mississippi ">Mississippi </asp:ListItem>
<asp:ListItem Value="Missouri ">Missouri </asp:ListItem>
<asp:ListItem Value="Montana ">Montana </asp:ListItem>
<asp:ListItem Value="Nebraska ">Nebraska </asp:ListItem>
<asp:ListItem Value="Nevada">Nevada</asp:ListItem>
<asp:ListItem Value="New Hampshire ">New Hampshire </asp:ListItem>
<asp:ListItem Value="New Jersey ">New Jersey </asp:ListItem>
<asp:ListItem Value="New Mexico ">New Mexico </asp:ListItem>
<asp:ListItem Value="New York">New York</asp:ListItem>
<asp:ListItem Value="North Carolina ">North Carolina </asp:ListItem>
<asp:ListItem Value="North Dakota ">North Dakota </asp:ListItem>
<asp:ListItem Value="Ohio ">Ohio </asp:ListItem>
<asp:ListItem Value="Oklahoma">Oklahoma</asp:ListItem>
<asp:ListItem Value="Oregon ">Oregon </asp:ListItem>
<asp:ListItem Value="Pennsylvania ">Pennsylvania </asp:ListItem>
<asp:ListItem Value="Rhode Island ">Rhode Island </asp:ListItem>
<asp:ListItem Value="South Carolina ">South Carolina </asp:ListItem>
<asp:ListItem Value="South Dakota ">South Dakota </asp:ListItem>
<asp:ListItem Value="Tennessee ">Tennessee </asp:ListItem>
<asp:ListItem Value="Texas ">Texas </asp:ListItem>
<asp:ListItem Value="Utah ">Utah </asp:ListItem>
<asp:ListItem Value="Vermont">Vermont</asp:ListItem>
<asp:ListItem Value="Virginia ">Virginia </asp:ListItem>
<asp:ListItem Value="Washington ">Washington </asp:ListItem>
<asp:ListItem Value="West Virginia ">West Virginia </asp:ListItem>
<asp:ListItem Value="Wisconsin ">Wisconsin </asp:ListItem>
<asp:ListItem Value="Wyoming ">Wyoming </asp:ListItem>
<asp:ListItem Value="Other">Other</asp:ListItem>
</asp:dropdownlist><asp:textbox id="AGraduationDate" style="Z-INDEX:
127; LEFT: 368px; POSITION: absolute; TOP: 488px"
tabIndex="13" runat="server" BackColor="Gold"
BorderColor="Gold"></asp:textbox><asp:dropdownlist id="Lstate" style="Z-
INDEX: 125; LEFT: 168px; POSITION: absolute; TOP: 312px" tabIndex="7"
runat="server" CssClass="gold" BackColor="Gold" Width="120px">
<asp:ListItem Value="Alabama">Alabama</asp:ListItem>
<asp:ListItem Value="Alaska ">Alaska </asp:ListItem>
<asp:ListItem Value="Arizona ">Arizona </asp:ListItem>
<asp:ListItem Value="Arkansas ">Arkansas </asp:ListItem>
<asp:ListItem Value="California ">California </asp:ListItem>
<asp:ListItem Value="Colorado ">Colorado </asp:ListItem>
<asp:ListItem Value=" Connecticut "> Connecticut </asp:ListItem>
<asp:ListItem Value="Delaware ">Delaware </asp:ListItem>
<asp:ListItem Value="Florida ">Florida </asp:ListItem>
<asp:ListItem Value="Georgia ">Georgia </asp:ListItem>
<asp:ListItem Value="Hawaii ">Hawaii </asp:ListItem>
<asp:ListItem Value="Idaho ">Idaho </asp:ListItem>
<asp:ListItem Value="Illinois ">Illinois </asp:ListItem>
<asp:ListItem Value="Indiana ">Indiana </asp:ListItem>
<asp:ListItem Value="Iowa ">Iowa </asp:ListItem>
<asp:ListItem Value="Kansas ">Kansas </asp:ListItem>
<asp:ListItem Value="Kentucky ">Kentucky </asp:ListItem>
<asp:ListItem Value="Louisiana">Louisiana</asp:ListItem>
<asp:ListItem Value="Maine ">Maine </asp:ListItem>
<asp:ListItem Value="Maryland ">Maryland </asp:ListItem>
<asp:ListItem Value="Massachusetts ">Massachusetts </asp:ListItem>
<asp:ListItem Value="Michigan ">Michigan </asp:ListItem>
<asp:ListItem Value="Minnesota ">Minnesota </asp:ListItem>
<asp:ListItem Value="Mississippi ">Mississippi </asp:ListItem>
<asp:ListItem Value="Missouri ">Missouri </asp:ListItem>
<asp:ListItem Value="Montana ">Montana </asp:ListItem>
<asp:ListItem Value="Nebraska ">Nebraska </asp:ListItem>
<asp:ListItem Value="Nevada">Nevada</asp:ListItem>
<asp:ListItem Value="New Hampshire ">New Hampshire </asp:ListItem>
<asp:ListItem Value="New Jersey ">New Jersey </asp:ListItem>
<asp:ListItem Value="New Mexico ">New Mexico </asp:ListItem>
<asp:ListItem Value="New York">New York</asp:ListItem>
<asp:ListItem Value="North Carolina ">North Carolina </asp:ListItem>
<asp:ListItem Value="North Dakota ">North Dakota </asp:ListItem>
<asp:ListItem Value="Ohio ">Ohio </asp:ListItem>
<asp:ListItem Value="Oklahoma">Oklahoma</asp:ListItem>
<asp:ListItem Value="Oregon ">Oregon </asp:ListItem>
<asp:ListItem Value="Pennsylvania ">Pennsylvania </asp:ListItem>
<asp:ListItem Value="Rhode Island ">Rhode Island </asp:ListItem>
<asp:ListItem Value="South Carolina ">South Carolina </asp:ListItem>
<asp:ListItem Value="South Dakota ">South Dakota </asp:ListItem>
<asp:ListItem Value="Tennessee ">Tennessee </asp:ListItem>
<asp:ListItem Value="Texas ">Texas </asp:ListItem>
<asp:ListItem Value="Utah ">Utah </asp:ListItem>
<asp:ListItem Value="Vermont">Vermont</asp:ListItem>
<asp:ListItem Value="Virginia ">Virginia </asp:ListItem>
<asp:ListItem Value="Washington ">Washington </asp:ListItem>
<asp:ListItem Value="West Virginia ">West Virginia </asp:ListItem>
<asp:ListItem Value="Wisconsin ">Wisconsin </asp:ListItem>
<asp:ListItem Value="Wyoming ">Wyoming </asp:ListItem>
<asp:ListItem Selected="True"></asp:ListItem>
</asp:dropdownlist><asp:dropdownlist id="SClassification" style="Z-
INDEX: 124; LEFT: 320px; POSITION: absolute; TOP: 448px"
tabIndex="12" runat="server" BackColor="Gold" Width="160px">
<asp:ListItem Selected="True"></asp:ListItem>
<asp:ListItem Value="Sophomore">Sophomore</asp:ListItem>
<asp:ListItem Value="Junior">Junior</asp:ListItem>
<asp:ListItem Value="Senior">Senior</asp:ListItem>
<asp:ListItem Value="Graduating Senior">Graduating Senior</asp:ListItem>
</asp:dropdownlist><asp:dropdownlist id="HoldVisa" style="Z-INDEX: 122;
LEFT: 392px; POSITION: absolute; TOP: 408px"
tabIndex="11" runat="server" BackColor="Gold">
<asp:ListItem Selected="True"></asp:ListItem>
<asp:ListItem Value="Yes">Yes</asp:ListItem>
<asp:ListItem Value="No">No</asp:ListItem>
</asp:dropdownlist><asp:label id="Label12" style="Z-INDEX: 121; LEFT:
120px; POSITION: absolute; TOP: 408px" runat="server"
CssClass="GoldNormalFont" Width="258px">Do you currently hold a student
visa?</asp:label><asp:dropdownlist id="USCitizen" style="Z-INDEX: 120;
LEFT: 496px; POSITION: absolute; TOP: 352px"
tabIndex="10" runat="server" BackColor="Gold" Width="88px">
<asp:ListItem Selected="True"></asp:ListItem>
<asp:ListItem Value="yes">yes</asp:ListIte

--
Message posted via http://www.dotnetmonster.com
Nov 19 '05 #1
5 4195
Vigneshwar:
Please do not use AS MANY UPPER CASE LETTERS IN YOUR MESSAGE. Also, it's
helpful if you simplify your problem to some basic examples so that we don't
have to go through large amounts of code.

Your code doesn't make too much sense to me. You are selecting a single
result set and storing that in a datareader. You then attempt to
continously bind to that datareader.

Maybe this is what you want to do:
Lstate.SelectedIndex =
Lstate.Items.IndexOf(Lstate.Items.FindByValue(dr["Lstate"]));

It seems like all the values are hardcoded into your dropdown and all you
want to do is pick the selected one?

Karl
--
MY ASP.Net tutorials
http://www.openmymind.net/ - New and Improved (yes, the popup is annoying)
http://www.openmymind.net/faq.aspx - unofficial newsgroup FAQ (more to
come!)
"Vigneshwar Pilli via DotNetMonster.com" <fo***@DotNetMonster.com> wrote in
message news:02******************************@DotNetMonste r.com...
string connectionString1 = "server=(local); user=sa;password=sa;
database=sonic";

System.Data.SqlClient.SqlConnection dbConnection1 = new
System.Data.SqlClient.SqlConnection(connectionStri ng1);
System.Data.SqlClient.SqlCommand dbCommand1 = new
System.Data.SqlClient.SqlCommand();


string sql="Select * From Student_SDS Where SSN='" + Session["SSN"] +
"'";
dbCommand1 = new SqlCommand (sql, dbConnection1);
dbConnection1.Open();
SqlDataReader dr = dbCommand1.ExecuteReader();
dr.Read();

LName.Text = Convert.ToString(dr["LName"]);
FName.Text= Convert.ToString(dr["FName"]);
MName.Text= Convert.ToString(dr["MName"]);
LocalAddress.Text= Convert.ToString(dr["LocalAddress"]);
Lcity.Text=Convert.ToString(dr["Lcity"]);
Lzip.Text=Convert.ToString(dr["Lzip"]);
BirthDate.Text=Convert.ToString(dr["BirthDate"]);
SchoolName.Text=Convert.ToString(dr["SchoolName"]);
SchoolOrigin.Text=Convert.ToString(dr["SchoolOrigin"]);
AGraduationDate.Text=Convert.ToString(dr["AGraduationDate"]);
Lstate.DataSource=dr;
Lstate.DataTextField="Lstate";
Lstate.DataBind();
USCitizen.DataSource=dr;
USCitizen.DataTextField="USCitizen";
USCitizen.DataBind();
SClassification.DataSource=dr;
SClassification.DataTextField="SClassification";
SClassification.DataBind();
SchoolState.DataSource=dr;
SchoolState.DataTextField="SchoolState";
SchoolState.DataBind();
SDSApplied.DataSource=dr;
SDSApplied.DataTextField="SDSApplied";
SDSApplied.DataBind();
LoanApplied.DataSource=dr;
LoanApplied.DataSource="LoanApplied";
LoanApplied.DataBind();
NursProg.DataSource=dr;
NursProg.DataTextField="NursProg";
NursProg.DataBind();
ProgType.DataSource=dr;
ProgType.DataTextField="ProgType";
ProgType.DataBind();
AwardWilling.DataSource=dr;
AwardWilling.DataTextField="AwardWilling";
AwardWilling.DataBind();
StayType.DataSource=dr;
StayType.DataTextField="StayType";
StayType.DataBind();
ParentGrad.DataSource=dr;
ParentGrad.DataTextField="ParentGrad";
ParentGrad.DataBind();
FirstStudy.DataSource=dr;
FirstStudy.DataTextField="FirstStudy";
FirstStudy.DataBind();
EnrollmentType.DataSource=dr;
EnrollmentType.DataTextField="EnrollmentType";
EnrollmentType.DataBind();
EnrollmentTerm.DataSource=dr;
EnrollmentTerm.DataTextField="EnrollmentTerm";
EnrollmentTerm.DataBind();
HoldVisa.DataSource=dr;
HoldVisa.DataMember="HoldVisa";
HoldVisa.DataTextField="HoldVisa";
HoldVisa.DataBind();
dr.Close();
dbConnection1.Close();

Well Here this code was for when PAGE LOAD.

Well The desired data was being Binded to the TEXT BOXES but.... THE DROP
DOWN LIST BOXES arent displaying anything... I donot know what the error
is. I wish some one could help me solve this or point the Error Out.
Well and the --------- code of each Drop DOwn List Boxes Initially designed as........
WELL BELOW IS THE ASP DROP DOWN LIST CODE..... WHEN INITIALLY DESIGNED THIS FORM.

I JUST WANT TO KNOW WHY THE DATA IS NOT BEING DISPLAYED BY THE ... DROP
DOWN LIST BOXES.

PLEASE HELP ME OUT.
WELL ONE MORE THING IS THAT---- THE TEXT AND THE VALUE ARE THE SAME -----
FOR THE DROP DOWN LIST ITEMS.

LIKE FOR THE NAME --- ARKANSAS> the VALUE WAS ALSO SET TO ARKANSAS.

SO I donot know how to retrieve the data in the database and to bind to
these controls.
Initially when the user fills the data from the drop down lists is added
into the database and when he second time comes in for editing the data, I
wish to show him the items he chose, I was successful in Binding the data
to ... TEXTBOXES but not to these Drop Down List Boxes.

SOME ONE PLEASE HELP ME OUT.
THANKS AND REGARDS>
WAITING FOR AN EARLY RESPONSE>

viggi.

<asp:dropdownlist id="SchoolState" style="Z-INDEX: 159; LEFT: 504px;
POSITION: absolute; TOP: 536px"
tabIndex="15" runat="server" BackColor="Gold" Width="120px">
<asp:ListItem Selected="True"></asp:ListItem>
<asp:ListItem Value="Alabama">Alabama</asp:ListItem>
<asp:ListItem Value="Alaska ">Alaska </asp:ListItem>
<asp:ListItem Value="Arizona ">Arizona </asp:ListItem>
<asp:ListItem Value="Arkansas ">Arkansas </asp:ListItem>
<asp:ListItem Value="California ">California </asp:ListItem>
<asp:ListItem Value="Colorado ">Colorado </asp:ListItem>
<asp:ListItem Value=" Connecticut "> Connecticut </asp:ListItem>
<asp:ListItem Value="Delaware ">Delaware </asp:ListItem>
<asp:ListItem Value="Florida ">Florida </asp:ListItem>
<asp:ListItem Value="Georgia ">Georgia </asp:ListItem>
<asp:ListItem Value="Hawaii ">Hawaii </asp:ListItem>
<asp:ListItem Value="Idaho ">Idaho </asp:ListItem>
<asp:ListItem Value="Illinois ">Illinois </asp:ListItem>
<asp:ListItem Value="Indiana ">Indiana </asp:ListItem>
<asp:ListItem Value="Iowa ">Iowa </asp:ListItem>
<asp:ListItem Value="Kansas ">Kansas </asp:ListItem>
<asp:ListItem Value="Kentucky ">Kentucky </asp:ListItem>
<asp:ListItem Value="Louisiana">Louisiana</asp:ListItem>
<asp:ListItem Value="Maine ">Maine </asp:ListItem>
<asp:ListItem Value="Maryland ">Maryland </asp:ListItem>
<asp:ListItem Value="Massachusetts ">Massachusetts </asp:ListItem>
<asp:ListItem Value="Michigan ">Michigan </asp:ListItem>
<asp:ListItem Value="Minnesota ">Minnesota </asp:ListItem>
<asp:ListItem Value="Mississippi ">Mississippi </asp:ListItem>
<asp:ListItem Value="Missouri ">Missouri </asp:ListItem>
<asp:ListItem Value="Montana ">Montana </asp:ListItem>
<asp:ListItem Value="Nebraska ">Nebraska </asp:ListItem>
<asp:ListItem Value="Nevada">Nevada</asp:ListItem>
<asp:ListItem Value="New Hampshire ">New Hampshire </asp:ListItem>
<asp:ListItem Value="New Jersey ">New Jersey </asp:ListItem>
<asp:ListItem Value="New Mexico ">New Mexico </asp:ListItem>
<asp:ListItem Value="New York">New York</asp:ListItem>
<asp:ListItem Value="North Carolina ">North Carolina </asp:ListItem>
<asp:ListItem Value="North Dakota ">North Dakota </asp:ListItem>
<asp:ListItem Value="Ohio ">Ohio </asp:ListItem>
<asp:ListItem Value="Oklahoma">Oklahoma</asp:ListItem>
<asp:ListItem Value="Oregon ">Oregon </asp:ListItem>
<asp:ListItem Value="Pennsylvania ">Pennsylvania </asp:ListItem>
<asp:ListItem Value="Rhode Island ">Rhode Island </asp:ListItem>
<asp:ListItem Value="South Carolina ">South Carolina </asp:ListItem>
<asp:ListItem Value="South Dakota ">South Dakota </asp:ListItem>
<asp:ListItem Value="Tennessee ">Tennessee </asp:ListItem>
<asp:ListItem Value="Texas ">Texas </asp:ListItem>
<asp:ListItem Value="Utah ">Utah </asp:ListItem>
<asp:ListItem Value="Vermont">Vermont</asp:ListItem>
<asp:ListItem Value="Virginia ">Virginia </asp:ListItem>
<asp:ListItem Value="Washington ">Washington </asp:ListItem>
<asp:ListItem Value="West Virginia ">West Virginia </asp:ListItem>
<asp:ListItem Value="Wisconsin ">Wisconsin </asp:ListItem>
<asp:ListItem Value="Wyoming ">Wyoming </asp:ListItem>
<asp:ListItem Value="Other">Other</asp:ListItem>
</asp:dropdownlist><asp:textbox id="AGraduationDate" style="Z-INDEX:
127; LEFT: 368px; POSITION: absolute; TOP: 488px"
tabIndex="13" runat="server" BackColor="Gold"
BorderColor="Gold"></asp:textbox><asp:dropdownlist id="Lstate" style="Z-
INDEX: 125; LEFT: 168px; POSITION: absolute; TOP: 312px" tabIndex="7"
runat="server" CssClass="gold" BackColor="Gold" Width="120px">
<asp:ListItem Value="Alabama">Alabama</asp:ListItem>
<asp:ListItem Value="Alaska ">Alaska </asp:ListItem>
<asp:ListItem Value="Arizona ">Arizona </asp:ListItem>
<asp:ListItem Value="Arkansas ">Arkansas </asp:ListItem>
<asp:ListItem Value="California ">California </asp:ListItem>
<asp:ListItem Value="Colorado ">Colorado </asp:ListItem>
<asp:ListItem Value=" Connecticut "> Connecticut </asp:ListItem>
<asp:ListItem Value="Delaware ">Delaware </asp:ListItem>
<asp:ListItem Value="Florida ">Florida </asp:ListItem>
<asp:ListItem Value="Georgia ">Georgia </asp:ListItem>
<asp:ListItem Value="Hawaii ">Hawaii </asp:ListItem>
<asp:ListItem Value="Idaho ">Idaho </asp:ListItem>
<asp:ListItem Value="Illinois ">Illinois </asp:ListItem>
<asp:ListItem Value="Indiana ">Indiana </asp:ListItem>
<asp:ListItem Value="Iowa ">Iowa </asp:ListItem>
<asp:ListItem Value="Kansas ">Kansas </asp:ListItem>
<asp:ListItem Value="Kentucky ">Kentucky </asp:ListItem>
<asp:ListItem Value="Louisiana">Louisiana</asp:ListItem>
<asp:ListItem Value="Maine ">Maine </asp:ListItem>
<asp:ListItem Value="Maryland ">Maryland </asp:ListItem>
<asp:ListItem Value="Massachusetts ">Massachusetts </asp:ListItem>
<asp:ListItem Value="Michigan ">Michigan </asp:ListItem>
<asp:ListItem Value="Minnesota ">Minnesota </asp:ListItem>
<asp:ListItem Value="Mississippi ">Mississippi </asp:ListItem>
<asp:ListItem Value="Missouri ">Missouri </asp:ListItem>
<asp:ListItem Value="Montana ">Montana </asp:ListItem>
<asp:ListItem Value="Nebraska ">Nebraska </asp:ListItem>
<asp:ListItem Value="Nevada">Nevada</asp:ListItem>
<asp:ListItem Value="New Hampshire ">New Hampshire </asp:ListItem>
<asp:ListItem Value="New Jersey ">New Jersey </asp:ListItem>
<asp:ListItem Value="New Mexico ">New Mexico </asp:ListItem>
<asp:ListItem Value="New York">New York</asp:ListItem>
<asp:ListItem Value="North Carolina ">North Carolina </asp:ListItem>
<asp:ListItem Value="North Dakota ">North Dakota </asp:ListItem>
<asp:ListItem Value="Ohio ">Ohio </asp:ListItem>
<asp:ListItem Value="Oklahoma">Oklahoma</asp:ListItem>
<asp:ListItem Value="Oregon ">Oregon </asp:ListItem>
<asp:ListItem Value="Pennsylvania ">Pennsylvania </asp:ListItem>
<asp:ListItem Value="Rhode Island ">Rhode Island </asp:ListItem>
<asp:ListItem Value="South Carolina ">South Carolina </asp:ListItem>
<asp:ListItem Value="South Dakota ">South Dakota </asp:ListItem>
<asp:ListItem Value="Tennessee ">Tennessee </asp:ListItem>
<asp:ListItem Value="Texas ">Texas </asp:ListItem>
<asp:ListItem Value="Utah ">Utah </asp:ListItem>
<asp:ListItem Value="Vermont">Vermont</asp:ListItem>
<asp:ListItem Value="Virginia ">Virginia </asp:ListItem>
<asp:ListItem Value="Washington ">Washington </asp:ListItem>
<asp:ListItem Value="West Virginia ">West Virginia </asp:ListItem>
<asp:ListItem Value="Wisconsin ">Wisconsin </asp:ListItem>
<asp:ListItem Value="Wyoming ">Wyoming </asp:ListItem>
<asp:ListItem Selected="True"></asp:ListItem>
</asp:dropdownlist><asp:dropdownlist id="SClassification" style="Z-
INDEX: 124; LEFT: 320px; POSITION: absolute; TOP: 448px"
tabIndex="12" runat="server" BackColor="Gold" Width="160px">
<asp:ListItem Selected="True"></asp:ListItem>
<asp:ListItem Value="Sophomore">Sophomore</asp:ListItem>
<asp:ListItem Value="Junior">Junior</asp:ListItem>
<asp:ListItem Value="Senior">Senior</asp:ListItem>
<asp:ListItem Value="Graduating Senior">Graduating Senior</asp:ListItem>
</asp:dropdownlist><asp:dropdownlist id="HoldVisa" style="Z-INDEX: 122;
LEFT: 392px; POSITION: absolute; TOP: 408px"
tabIndex="11" runat="server" BackColor="Gold">
<asp:ListItem Selected="True"></asp:ListItem>
<asp:ListItem Value="Yes">Yes</asp:ListItem>
<asp:ListItem Value="No">No</asp:ListItem>
</asp:dropdownlist><asp:label id="Label12" style="Z-INDEX: 121; LEFT:
120px; POSITION: absolute; TOP: 408px" runat="server"
CssClass="GoldNormalFont" Width="258px">Do you currently hold a student
visa?</asp:label><asp:dropdownlist id="USCitizen" style="Z-INDEX: 120;
LEFT: 496px; POSITION: absolute; TOP: 352px"
tabIndex="10" runat="server" BackColor="Gold" Width="88px">
<asp:ListItem Selected="True"></asp:ListItem>
<asp:ListItem Value="yes">yes</asp:ListIte

--
Message posted via http://www.dotnetmonster.com

Nov 19 '05 #2
Hey,
Well it is that....

Initially when I designed the form, I added the items for the Respective
Drop Down Lists.

Like for .. State-- I added all the 50 states, so the user can select them.
similarly to all the rest of drop down list boxes to their values, like yes
no and so on.

and I wrote the code to update the selected values into the database---
from the button click event.

so, Here what the Problem I have is, when the user logs in again after once
filling the information.

I am just trying to pull the data from the DATABASE and bind it to the
respective Controls( TEXT BOXES and DROP DOWN LIST BOXES).

So that the user can modify the data until he is totally finished with the
editing, every time he logs in, this happens till he clicks submit totally--
- after he clicks he cannot see his form any more.
So, I am trying to Bind the Data from the Database to the respective
controls ----pertaining to that Persons record.

I succeeded binding it to the TEXT BOXES but not able to Bind it to the
Drop Down List Controls. ( BRINGING THE INFORMATION FROM THE DATABASE TO
THE EXISTING CONTROLS)
// DECLARATION OF DATABASE CONNECTION.
System.Data.SqlClient.SqlConnection dbConnection1 = new
System.Data.SqlClient.SqlConnection(connectionStri ng1);
System.Data.SqlClient.SqlCommand dbCommand1 = new
Systemm.Data.SqlClient.SqlCommand();
string sql="Select * From Student_SDS Where SSN='" + Session["SSN"] +
"'";
dbCommand1 = new SqlCommand (sql, dbConnection1);
dbConnection1.Open();
SqlDataReader dr = dbCommand1.ExecuteReader();// DELCARATION OF DATA READER
dr.Read();

LName.Text = Convert.ToString(dr["LName"]); // successfull in bringing the
information from database and displaying it into the respective text box.

// trying to get the value of the "state" the user selected last time
which is stored in the DATABASE.

Lstate.DataSource=dr;
Lstate.DataTextField="Lstate";
Lstate.DataBind();
This is what was given in the TEXT BOOK UNLEASHED.

I am a beginner, working on a part time basis to... do these Server pages..
and I have no much Idea, other than what given in te BOOK " ASp .NET
UNLEASHED".

SO... The Main Problem is that I got to BIND the DATA TO ALL OF THE DROP
DOWN LIST BOXES IN THE FORM, WHICH HOLD SOME VALUES..

I HAVE TO BIND THE DATA -- INTO THE DROP DOWN LIST BOXES, allowing the user
to make changes if he wants to.
So please let me some meathod... how to bind the data in the Database to
the DROP DOWN LIST CONTROLS.
so that I can solve this Problem.

Please Help me Out.

--
Message posted via http://www.dotnetmonster.com
Nov 19 '05 #3
Vigneshwar:
All all 50 states still manually entered in the designer?

Binding is the act of taking database rows and generating controls from
that. You don't BIND to a textbox, you simply set it's value from a
database. If you want to bind the state, you'd do something like:
command.CommandText = "SELECT StateId, StateName FROM States"
dr = command.ExecuteReader()
Lstate.DataSouce = dr
LState.DataTextField = "StateName"
LSate.DataValueField = "StateId"
Lstate.DataBind()
(this is just some pseudo code, but you should get hte idea)

this will add an item for each row in the states table.
if you wanted to highlight the user's specific state you would do:
command.CommandText = "Select UserId, StateId, .... FROM Users where UserId
= 1"
dr = command.ExecuteReader()

lstate.Items.SelectedIndex =
LState.Items.IndexOf(LState.Items.FindByValue(dr["StateId"].ToString()))
in the 1st example, you are BINDIND data to the dropdownlist

in the 2nd example, you are setting the value
if you are hard-coding all the states, you don't do the 1st part....my guess
is all you want is the 2nd part....
Karl
--
MY ASP.Net tutorials
http://www.openmymind.net/ - New and Improved (yes, the popup is annoying)
http://www.openmymind.net/faq.aspx - unofficial newsgroup FAQ (more to
come!)
"Vigneshwar Pilli via DotNetMonster.com" <fo***@DotNetMonster.com> wrote in
message news:76******************************@DotNetMonste r.com...
Hey,
Well it is that....

Initially when I designed the form, I added the items for the Respective
Drop Down Lists.

Like for .. State-- I added all the 50 states, so the user can select them. similarly to all the rest of drop down list boxes to their values, like yes no and so on.

and I wrote the code to update the selected values into the database---
from the button click event.

so, Here what the Problem I have is, when the user logs in again after once filling the information.

I am just trying to pull the data from the DATABASE and bind it to the
respective Controls( TEXT BOXES and DROP DOWN LIST BOXES).

So that the user can modify the data until he is totally finished with the
editing, every time he logs in, this happens till he clicks submit totally-- - after he clicks he cannot see his form any more.
So, I am trying to Bind the Data from the Database to the respective
controls ----pertaining to that Persons record.

I succeeded binding it to the TEXT BOXES but not able to Bind it to the
Drop Down List Controls. ( BRINGING THE INFORMATION FROM THE DATABASE TO
THE EXISTING CONTROLS)
// DECLARATION OF DATABASE CONNECTION.
System.Data.SqlClient.SqlConnection dbConnection1 = new
System.Data.SqlClient.SqlConnection(connectionStri ng1);
System.Data.SqlClient.SqlCommand dbCommand1 = new
Systemm.Data.SqlClient.SqlCommand();
string sql="Select * From Student_SDS Where SSN='" + Session["SSN"] +
"'";
dbCommand1 = new SqlCommand (sql, dbConnection1);
dbConnection1.Open();
SqlDataReader dr = dbCommand1.ExecuteReader();// DELCARATION OF DATA READER dr.Read();

LName.Text = Convert.ToString(dr["LName"]); // successfull in bringing the information from database and displaying it into the respective text box.

// trying to get the value of the "state" the user selected last time
which is stored in the DATABASE.

Lstate.DataSource=dr;
Lstate.DataTextField="Lstate";
Lstate.DataBind();
This is what was given in the TEXT BOOK UNLEASHED.

I am a beginner, working on a part time basis to... do these Server pages.. and I have no much Idea, other than what given in te BOOK " ASp .NET
UNLEASHED".

SO... The Main Problem is that I got to BIND the DATA TO ALL OF THE DROP
DOWN LIST BOXES IN THE FORM, WHICH HOLD SOME VALUES..

I HAVE TO BIND THE DATA -- INTO THE DROP DOWN LIST BOXES, allowing the user to make changes if he wants to.
So please let me some meathod... how to bind the data in the Database to
the DROP DOWN LIST CONTROLS.
so that I can solve this Problem.

Please Help me Out.

--
Message posted via http://www.dotnetmonster.com

Nov 19 '05 #4
Oo Karl,

thanks very much man,

I just needed the second part, anyways there is small error in the syntax u
sent --- it would be like this.
Income.SelectedIndex=Income.Items.IndexOf(Income.I tems.FindByValue(dr
["Income"].ToString()));
Well Another small Problem Dear,

well how can I take a DateTime Variable into the DataBase from the Form,

If I use a Stored Procedure for.. inserting the data,

whats is the syntax or ... declaration of...the parameters.... for the
datetime variable.

well I mean it was.....

see here below... this is the way I am adding with the parameter for the
text box variable.

dbCommand.Parameters.Add("@FAFSAApplied",@FAFSAApp lied.SelectedValue );
// this is for the DROP DOWN LIST VARIABLE //
dbCommand.Parameters.Add("@FName",@FName.text); // for text box//
dbCommand.Parameters.Add . HOW ?? for is the value to be inserted into
the database is a DATETIME variable. I need how to declare for my method.

plzz lemme know bye and take care.
how about to.. add if the input I take from the text box is a DATETIME
value represented in the database. how can I declare.

Plz... lemme know..

anyways many thanks for ur solution. worked well.
thanks and regards,
viggi
dbCommand.Parameters.Add("@FAFSAApplied",@FAFSAApp lied.SelectedValue );

--
Message posted via http://www.dotnetmonster.com
Nov 19 '05 #5
You should be able to add a datetime the same way:

dbCommand.Parameters.Add("@From").Value = fromTextBox.Text

The only problem is tha tyou need to make sure that fromTextBox.Text is a
valid date/time field....,you can do this by validating the user input...

Karl
--
MY ASP.Net tutorials
http://www.openmymind.net/ - New and Improved (yes, the popup is
annoying)
http://www.openmymind.net/faq.aspx - unofficial newsgroup FAQ (more to
come!)
"Vigneshwar Pilli via DotNetMonster.com" <fo***@DotNetMonster.com> wrote in
message news:05******************************@DotNetMonste r.com...
Oo Karl,

thanks very much man,

I just needed the second part, anyways there is small error in the syntax u sent --- it would be like this.
Income.SelectedIndex=Income.Items.IndexOf(Income.I tems.FindByValue(dr
["Income"].ToString()));
Well Another small Problem Dear,

well how can I take a DateTime Variable into the DataBase from the Form,

If I use a Stored Procedure for.. inserting the data,

whats is the syntax or ... declaration of...the parameters.... for the
datetime variable.

well I mean it was.....

see here below... this is the way I am adding with the parameter for the
text box variable.

dbCommand.Parameters.Add("@FAFSAApplied",@FAFSAApp lied.SelectedValue );
// this is for the DROP DOWN LIST VARIABLE //
dbCommand.Parameters.Add("@FName",@FName.text); // for text box//
dbCommand.Parameters.Add . HOW ?? for is the value to be inserted into
the database is a DATETIME variable. I need how to declare for my method.
plzz lemme know bye and take care.
how about to.. add if the input I take from the text box is a DATETIME
value represented in the database. how can I declare.

Plz... lemme know..

anyways many thanks for ur solution. worked well.
thanks and regards,
viggi
dbCommand.Parameters.Add("@FAFSAApplied",@FAFSAApp lied.SelectedValue );

--
Message posted via http://www.dotnetmonster.com

Nov 19 '05 #6

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

Similar topics

0
by: Jason | last post by:
What interface do I need to implement in order to get a component with a public property to show up in the data binding drop down boxes at design time in VS.net? I've tried to look just about...
6
by: Robin Bonin | last post by:
In my user contol I am creating a set of dropdownlists. Each list is created based on input from the other lists. The problem I am having is setting the selected index on the lists. If someone...
2
by: Andrea Williams | last post by:
I have a drop down control that I've added a list item that has a value of zero and the text name is "". And it shows up like it's supposed to until I bind a dataset to it. The binding seems to...
9
by: Matt Tapia | last post by:
I having a problem that receives the following error: Specified cast is not valid And I need some help. Here is what is happening: I have a form with a drop-down control that contains a list...
7
by: Girish | last post by:
OK.. phew. Playing with data grids for the past few days has been fun and a huge learning experience.. My problem. I have a requirement to display a gird with a gird. Within the embedded grid,...
0
by: dutone | last post by:
I have searched high and low for a solution to this and I dont think its possible.... but I hope not. What I have is a list of items with various values that can be changed via a drop down. Each...
1
by: MikeB | last post by:
ooh boy, I hope I'm in the right place to ask this. I'm trying to do a class project that binds controls to data sources. I have a Drop-down List that I bound to the Author column of an SQL...
9
by: =?Utf-8?B?VGVycnk=?= | last post by:
Think it is great the way that you can set up a datsource, value member, and display member for a combobox, and map a 'code' to a 'description' and back again by binding the combobox to a...
0
by: Leon Mayne | last post by:
We have static functions in our data access layer that return generic lists of our business objects, such as this: Public Shared Function AllUsers() as Generic.IList(of OurUserObject) Dim...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
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
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:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.