How to access datagrid on web page from user control on the samepage

  • Thread starter Thread starter Yanesh Tyagi
  • Start date Start date
Y

Yanesh Tyagi

Hi All

have a web page named itemList.aspx. It contains a datagrid (id =
datagrid1). The web form also have a user control named itemSearch.ascx.
This user control have several options to search and a submit button. I
want to change the datasource property of datagrid1 on the click of
submit button. As the datagrid1 is on the itemList.aspx page and the
submit button is on the user control, I connot access the datagrid
directly. Is there any way to acess it from the .vb file of user control?

Thanks

Yanesh Tyagi
 
Hi Yanesh Tyagi,

You could use FindControl() to find the datagrid which is in aspx page.

Here is the sample code.

Dim conn As System.Data.OleDb.OleDbConnection = New
System.Data.OleDb.OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;
Data Source=NWIND.mdb")
Dim da As System.Data.OleDb.OleDbDataAdapter = New
System.Data.OleDb.OleDbDataAdapter("select * from categories", conn)
Dim dataSet As DataSet = New DataSet
da.Fill(dataSet)
Dim dg As DataGrid = CType(Me.Page.FindControl("DataGrid1"), DataGrid)
dg.DataSource = dataSet
dg.DataBind()

-Bhuva
[www.syncfusion.com
http://www.syncfusion.com/faq/aspnet/default.aspx]
 
Back
Top