Click to See Complete Forum and Search --> : page events


zacharya
May 11th, 2004, 12:40 AM
I'm new with asp.net and just learn it a couple days ago.
I'm a little bit confused with page events in the web form, when they are being called....

I found it confusing because when I tried adding a data grid to my web form, I want the data adapter to call its Fill(dataset) method so the datagrid can use the dataset fo populate the table.

But somehow I don't know where to put my code for calling the Fill() method and DataGrid.bind()

I tried to use it in the page_load but it didn't work instead it shows me error message....

can you help me with this problem.


thanks before....:)

ABudair
May 23rd, 2004, 08:12 AM
Hi,

the filling of data grid is working according to the event that u want to handle it.

anyway if u want to fill the data grid into the page_load event handler the code at the bottom, another thing send me the error message that appeared.

try this..

private void Page_load ()
{

DataGrid1.DataSource = this.DataSource();
DataGrid1.DataBind();

}

private DataTable DataSource()
{
SqlConnection conn = new ...
SqlCommand command = new ...
DataTable dt = new DataTable();
command.cmdText = "select * from users";
SqlDataAdapter da = new SqlDataAdapter(command);
da.fill(ds);
return dt;
}

It should be work fine,
Hope it helps..

Bye.

TheCPUWizard
May 23rd, 2004, 08:15 AM
private void Page_load ()
{
if (!IsPostBack)
{
DataGrid1.DataSource = this.DataSource();
DataGrid1.DataBind();
}
}


Otherwise...

a) you will induce un-necessary overhead if the data is not editable.

b) you will wipe out and edits before you can process them.

ABudair
May 23rd, 2004, 08:29 AM
Hi,

Sure as u said.

using of !IsPostBack is too important for application overhead loading and effeciency.

Good work and thanx - TheCPUWizard- :) .