v-wywang
Wed Jul 25 04:42:39 CDT 2007
Dear Acsla,
Thanks for Brandon's response.
Actually, this is a known issue in Asp.net 2.0 Application.
asp.net 2.0 databound controls will automatically do the databinding when
the DataSourceID is configured... Also, this automatic databinding is
performed during the PreRender event
If you want to get rid of automatic databinding, 1) Brandon's idea is a
good solution.
2) For another choice, I'd like to suggest you use DBDataAdapter/DataSet
rather than DataSource Control. DataSource Control is a new component in
ASP.net 2.0. ASP.net 2.0 will retrieve data from DataSource control
automatically when we assign it to DataGrid.DataSourceID in design mode.
You can fill dataset by DataAdapter and set dataset to DataGrid.DataSource
property.
Call DataGrid.DataBind() method when necessary.
For example:
SqlConnection cn=new SqlConnection();
SqlCommand scd=new SqlCommand()
SqlDataAdatper sda=new SqlDataAdapter(scd,cn);
DataSet ds=new DataSet();
Sda.Fill(ds);
this.DataGrid1.DataSource=ds;
this.DataGrid1.DataBind();
3) Steven provided two solutions (set DataSourceID in runtime or get the
IEnumerable collection from DataSouce Contol.) for such issue.
a. Assign the DataSourceID at runtime (in a certain of your control's
postback event) and call databind method....
b. Call DataSourceControl.Select method to get the IEnumerable
collection (datasource object) and assign it to DataBoundControl.DataSource
property and call databind method.
http://groups.google.com/group/microsoft.public.dotnet.framework.aspnet/brow
se_thread/thread/b44e282bb0b0f95f/86036d48e0418053?lnk=st&q=ASP+Net+-+2.0+co
ntrolling+Databinding&rnum=3&hl=zh-CN#86036d48e0418053
[2.0 controlling Databinding ]
Hope this helps. Please feel free to let me know if you have anything
unclear. We are glad to assist you. Have a great day,
Sincerely,
Wen Yuan
Microsoft Online Community Support
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.