Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Datagrid class (Generic) ??????

Status
Not open for further replies.

Harish77

Programmer
Dec 25, 2001
18
US
Hi All,

I am working with a project using ASP.NET. It is an intranet project, and most of the data is displayed using datagrid.

Most of the screens I have Add records, edit records, delete, paging, filtering the data etc.

Now it becomes a repitative task to code for each page the datagrid functionality.

I was wondering if any one of you have come across a datagrid class which can be called whereever necessary and display the result. I checked in the web but I couldnt find anything like that. Please help if you have come across.

Thanks in Advance

Harish
 
You could write an ascx file that could make what your DataGrid does and then use that control in any page you want with the proper settings.

________
George, M
 
Thank you Shaddow, Sorry for asking, but do you have any sample code for doing this.
 
I've made a simple example
Code:
-LoginCtrl.ascx

<%@ Control Language=&quot;vb&quot; AutoEventWireup=&quot;false&quot; Codebehind=&quot;LoginCtrl.ascx.vb&quot; Inherits=&quot;CustomControl.LoginCtrl&quot; TargetSchema=&quot;[URL unfurl="true"]http://schemas.microsoft.com/intellisense/ie5&quot;[/URL] %>
<asp:Table HorizontalAlign=&quot;Center&quot; id=&quot;loginTable&quot; runat=&quot;server&quot;>
	<asp:TableRow>
		<asp:TableCell HorizontalAlign=&quot;Right&quot;>
			<font face=&quot;verdana&quot; size=&quot;1&quot;>Username:</font>
		</asp:TableCell>
		<asp:TableCell>
			<asp:TextBox ID=&quot;_uname&quot; Runat=&quot;server&quot;></asp:TextBox>
		</asp:TableCell>
	</asp:TableRow>
	<asp:TableRow>
		<asp:TableCell HorizontalAlign=&quot;Right&quot;>
			<font face=&quot;verdana&quot; size=&quot;1&quot;>Password:</font>
		</asp:TableCell>
		<asp:TableCell>
			<asp:TextBox ID=&quot;_password&quot; Runat=&quot;server&quot;></asp:TextBox>
		</asp:TableCell>
	</asp:TableRow>
	<asp:TableRow>
		<asp:TableCell ColumnSpan=&quot;2&quot; HorizontalAlign=&quot;Center&quot;>
			<asp:Button Runat=&quot;server&quot; Text=&quot;Login&quot; ID=&quot;LoginBtn&quot;></asp:Button>
		</asp:TableCell>
	</asp:TableRow>
</asp:Table>

-LoginCtrl.ascx.vb

Public MustInherit Class LoginCtrl
    Inherits System.Web.UI.UserControl
    Public _uname As TextBox
    Public _password As TextBox
#Region &quot; Web Form Designer Generated Code &quot;

    'This call is required by the Web Form Designer.
    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()

    End Sub

    Private Sub Page_Init(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Init
        'CODEGEN: This method call is required by the Web Form Designer
        'Do not modify it using the code editor.
        InitializeComponent()
    End Sub

#End Region
End Class


-WebForm1.aspx

<%@ Page Language=&quot;vb&quot; AutoEventWireup=&quot;false&quot; Codebehind=&quot;WebForm1.aspx.vb&quot; Inherits=&quot;CustomControl.WebForm1&quot;%>
<%@ Register TagPrefix=&quot;uc1&quot; TagName=&quot;LoginCtrl&quot; Src=&quot;LoginCtrl.ascx&quot; %>
<HTML>
	<HEAD>
	</HEAD>
	<body>
		<form id=&quot;Form1&quot; method=&quot;post&quot; runat=&quot;server&quot;>
			<uc1:loginctrl id=&quot;login&quot; runat=&quot;server&quot;></uc1:loginctrl></form>
	</body>
</HTML>

-WebForm1.aspx.vb

Imports CustomControl.LoginCtrl
Public Class WebForm1
    Inherits System.Web.UI.Page
    Protected login As LoginCtrl
#Region &quot; Web Form Designer Generated Code &quot;

    'This call is required by the Web Form Designer.
    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()

    End Sub

    Private Sub Page_Init(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Init
        'CODEGEN: This method call is required by the Web Form Designer
        'Do not modify it using the code editor.
        InitializeComponent()
    End Sub

#End Region

    Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        'Put user code to initialize the page here
        If IsPostBack() Then
            Dim Uname, Pwd As String
            Uname = login._uname.Text
            Pwd = login._password.Text
        End If
    End Sub

End Class

This should be the easyest way of making an Custom Control in my opinion, coding it's clean and simple.

________
George, M
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top