Problem Binding Data to DROP DOWN LIST CONTROL

  • Thread starter Vigneshwar Pilli via DotNetMonster.com
  • Start date
V

Vigneshwar Pilli via DotNetMonster.com

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

System.Data.SqlClient.SqlConnection dbConnection1 = new
System.Data.SqlClient.SqlConnection(connectionString1);
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
 
K

Karl Seguin

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 said:
string connectionString1 = "server=(local); user=sa;password=sa;
database=sonic";

System.Data.SqlClient.SqlConnection dbConnection1 = new
System.Data.SqlClient.SqlConnection(connectionString1);
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
 
V

Vigneshwar Pilli via DotNetMonster.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(connectionString1);
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.
 
K

Karl Seguin

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 said:
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(connectionString1);
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.
 
V

Vigneshwar Pilli via DotNetMonster.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.Items.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",@FAFSAApplied.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",@FAFSAApplied.SelectedValue );
 
K

Karl Seguin

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!)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,768
Messages
2,569,574
Members
45,051
Latest member
CarleyMcCr

Latest Threads

Top