very strange problem

V

Viktor Popov

Hi,

When I place the following coede in Page_Load method it doesn't populate the
DropDownList and when I place it in Button1_Click method and I push the
button after the page is loaded the DropDownList is populated. What I should
do in order to populate the DropDownList when I reach this WebForm by link
from another WebForm?


SqlConnection conn = new SqlConnection("Data Source=BLEK;Initial
Catalog=Estate; User ID=blek; Password=banderas");

SqlDataAdapter dad = new SqlDataAdapter ("SELECT
blek.TypeOffer.OfferID,blek.TypeOffer.TypeOffer FROM blek.TypeOffer", conn);

conn.Open();

dad.SelectCommand.ExecuteNonQuery();

DataTable table=new DataTable();

dad.Fill(table);

DropDownList2.DataSource=table;

DropDownList2.DataValueField = "OfferID";

DropDownList2.DataTextField = "TypeOffer";

DropDownList2.DataBind();

msg.Text = table.Rows.Count.ToString();

conn.Close();
 
V

Viktor Popov

Thanks for the reply!
How could I check that or to wired the Page_Load to the Load event ?
 
V

Viktor Popov

Thanks for the reply
Yes, I use if (!Page.IsPostBack)
{
code
}

Alvin Bruney said:
are you checking for page.ispostback in your pageload?

--
Regards,
Alvin Bruney
[ASP.NET MVP http://mvp.support.microsoft.com/default.aspx]
Got tidbits? Get it here... http://tinyurl.com/27cok
Viktor Popov said:
Hi,

When I place the following coede in Page_Load method it doesn't populate
the
DropDownList and when I place it in Button1_Click method and I push the
button after the page is loaded the DropDownList is populated. What I
should
do in order to populate the DropDownList when I reach this WebForm by link
from another WebForm?


SqlConnection conn = new SqlConnection("Data Source=BLEK;Initial
Catalog=Estate; User ID=blek; Password=banderas");

SqlDataAdapter dad = new SqlDataAdapter ("SELECT
blek.TypeOffer.OfferID,blek.TypeOffer.TypeOffer FROM blek.TypeOffer",
conn);

conn.Open();

dad.SelectCommand.ExecuteNonQuery();

DataTable table=new DataTable();

dad.Fill(table);

DropDownList2.DataSource=table;

DropDownList2.DataValueField = "OfferID";

DropDownList2.DataTextField = "TypeOffer";

DropDownList2.DataBind();

msg.Text = table.Rows.Count.ToString();

conn.Close();
 
V

Viktor Popov

I have done it:)
Thanks!
Viktor Popov said:
Hi,

When I place the following coede in Page_Load method it doesn't populate the
DropDownList and when I place it in Button1_Click method and I push the
button after the page is loaded the DropDownList is populated. What I should
do in order to populate the DropDownList when I reach this WebForm by link
from another WebForm?


SqlConnection conn = new SqlConnection("Data Source=BLEK;Initial
Catalog=Estate; User ID=blek; Password=banderas");

SqlDataAdapter dad = new SqlDataAdapter ("SELECT
blek.TypeOffer.OfferID,blek.TypeOffer.TypeOffer FROM blek.TypeOffer", conn);

conn.Open();

dad.SelectCommand.ExecuteNonQuery();

DataTable table=new DataTable();

dad.Fill(table);

DropDownList2.DataSource=table;

DropDownList2.DataValueField = "OfferID";

DropDownList2.DataTextField = "TypeOffer";

DropDownList2.DataBind();

msg.Text = table.Rows.Count.ToString();

conn.Close();
 

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

Forum statistics

Threads
473,772
Messages
2,569,593
Members
45,112
Latest member
BrentonMcc
Top