Asp.net GridView - how to access datasource before data is bound?

I'm trying to access datasource before I bind it to grid. How do I do that? My guess I should look in one of the events like Grid.DataBinding

Answer1:

Yes, the GridView.DataBinding event will be raised prior to the control being bound. You can access the DataSource control in that event and make modifications if you so desire (for example, modifying parameters).

protected void Grid_DataBinding(object sender, EventArgs e) { mySqlDataSource.SelectCommand = "Select * from Stars"; }

Answer2:

One way would be to not define the datasource on the grid itself. In the page_load, create and populate your datasource and then dynamically bind it to your datagrid. That way you would be able to access it.

Hope it helps!

人吐槽 人点赞

Recommend

Comment

用户名: 密码:
验证码: 匿名发表

你可以使用这些语言

查看评论:Asp.net GridView - how to access datasource before data is bound?