Click here to Skip to main content
15,888,351 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi Friends,

I want to have a gridview in user control
XML
<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="WebUserControl1.ascx.cs" Inherits="UserControlsDemo.WebUserControl1" %>

<asp:GridView ID="GridView1" runat="server"></asp:GridView>




If I execute WebForm1.aspx --> I want to display Table1 Data in GridView.
If I execute WebForm2.aspx --> I want to display Table2 Data in GridView.

How is it possible? I am waiting for your answer.


Thanks in advance
Reddy
Posted

1 solution

Very easy. Define a method in UserControl and bind the GridView there.

Refer - Bind gridview inside of usercontrol from content page[^].
C#
//in user control, add this method
public void BindGrid()
{
    gvInnerGrid.DataBind();
}

//on your page
userControl.BindGrid();
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900