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

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
 
S

santel

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]
 

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,776
Messages
2,569,603
Members
45,188
Latest member
Crypto TaxSoftware

Latest Threads

Top