Click here to Skip to main content
15,913,587 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have error when I run my profile page. because of drop down list didnot find.

I write my code in code behind file....



using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;

public partial class profile : System.Web.UI.Page
{
Logindata data = new Logindata();
Loginpropertylayer prop = new Loginpropertylayer();


DataSet ds = new DataSet();
SqlDataAdapter da = new SqlDataAdapter();
SqlCommand cmd = new SqlCommand();
SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["conn"].ToString());

protected void Page_Load(object sender, EventArgs e)
{

TextBox1.Visible = false;
TextBox2.Visible = false;
TextBox3.Visible = false;
TextBox4.Visible = false;
TextBox5.Visible = false;
TextBox6.Visible = false;
TextBox7.Visible = false;
TextBox8.Visible = false;
TextBox9.Visible = false;
DropDownList1.Visible=false;
DropDownList2.Visible=false;
RadioButtonList1.Visible=false;


if (!IsPostBack)
{
DataSet ds = new DataSet();

string uname = Session["login1"].ToString();
ds = data.getdata(uname);
Label2.Text = ds.Tables[0].Rows[0]["firstname"].ToString();
Label3.Text = ds.Tables[0].Rows[0]["lastname"].ToString();
Label4.Text = ds.Tables[0].Rows[0]["address"].ToString();
Label5.Text = ds.Tables[0].Rows[0]["birthdate"].ToString();
Label6.Text = ds.Tables[0].Rows[0]["state"].ToString();
Label7.Text = ds.Tables[0].Rows[0]["city"].ToString();
Label8.Text = ds.Tables[0].Rows[0]["Gender"].ToString();
Label9.Text = ds.Tables[0].Rows[0]["Education"].ToString();
Label10.Text = ds.Tables[0].Rows[0]["mobilenumber"].ToString();
Label11.Text = ds.Tables[0].Rows[0]["email"].ToString();
Label12.Text = ds.Tables[0].Rows[0]["username"].ToString();
Label13.Text = ds.Tables[0].Rows[0]["password"].ToString();
Image1.ImageUrl = ds.Tables[0].Rows[0]["Pic"].ToString();





}
}


protected void Button1_Click(object sender, EventArgs e)
{
Label2.Visible = false;
Label3.Visible = false;
Label4.Visible = false;
Label5.Visible = false;
Label6.Visible = false;
Label7.Visible = false;
Label8.Visible = false;
Label9.Visible = false;
Label10.Visible = false;
Label11.Visible = false;
Label12.Visible = false;
Label13.Visible = false;
DropDownList1.Visible = false;
DropDownList2.Visible = false;
RadioButtonList1.Visible = false;


TextBox1.Visible = true;
TextBox2.Visible = true;
TextBox3.Visible = true;
TextBox4.Visible = true;
TextBox5.Visible = true;
TextBox6.Visible = true;
TextBox7.Visible = true;
TextBox8.Visible = true;
TextBox9.Visible = true;
DropDownList1.Visible = true;
DropDownList2.Visible = true;
RadioButtonList1.Visible = true;


DataSet ds = new DataSet();

string uname = Session["login1"].ToString();
ds = data.getdata(uname);
TextBox1.Text = ds.Tables[0].Rows[0]["firstname"].ToString();
TextBox2.Text = ds.Tables[0].Rows[0]["lastname"].ToString();
TextBox3.Text = ds.Tables[0].Rows[0]["address"].ToString();
TextBox4.Text = ds.Tables[0].Rows[0]["birthdate"].ToString();
DropDownList1.Text = ds.Tables[0].Rows[0]["state"].ToString();
DropDownList2.Text = ds.Tables[0].Rows[0]["city"].ToString();

TextBox5.Text = ds.Tables[0].Rows[0]["Education"].ToString();
TextBox6.Text = ds.Tables[0].Rows[0]["mobilenumber"].ToString();
TextBox7.Text = ds.Tables[0].Rows[0]["email"].ToString();
TextBox8.Text = ds.Tables[0].Rows[0]["username"].ToString();
TextBox9.Text = ds.Tables[0].Rows[0]["password"].ToString();
Image1.ImageUrl = ds.Tables[0].Rows[0]["Pic"].ToString();

string strcntry = "sp_State";
da = new SqlDataAdapter(strcntry, con);
ds.Clear();
da.Fill(ds);
DropDownList1.DataTextField = "State";
DropDownList1.DataValueField = "SId";
DropDownList1.DataSource = ds;




string strcty = "sp_City";
da = new SqlDataAdapter(strcty, con);
ds.Clear();
da.Fill(ds);
DropDownList2.DataTextField = "cityName";
DropDownList2.DataValueField = "Cid";
DropDownList2.DataSource = ds;
DropDownList2.DataBind();





}


}
Posted

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900