473,382 Members | 1,658 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,382 software developers and data experts.

User Controls with in datagrids

Zi
I have a user control within a data grid. I am binding the user
control to one of the values from the data grid. The data grid
implements paging. It is all working ok for the first page but once i
page to the second page of the datagrid, the user contorl stops
working correctly (displaying the correct data).

I have attached the code that is envolved.

Thanks a lot

Regards,

Zi

======== USER CONTROL CODE============
-------- ASCX code -----------
<%@ Control Language="vb" AutoEventWireup="false"
Codebehind="AlertButton.ascx.vb"
Inherits="wcBulletinBoard.AlertButton"
TargetSchema="http://schemas.microsoft.com/intellisense/ie5" %>

<asp:ImageButton id="imgAlert" Runat="server" AlternateText="Click
here to add a watch to this title" ></asp:ImageButton>
<asp:TextBox Visible="true" ID="m_MessageID" Runat="server"/>
<asp:TextBox Visible="true" ID="m_intHasAlert" Runat="server"/>

-------- User contorl code behind -----------

Public Class AlertButton
Inherits System.Web.UI.UserControl

Protected WithEvents imgAlert As
System.Web.UI.WebControls.ImageButton
Protected WithEvents m_MessageID As
System.Web.UI.WebControls.TextBox
Protected WithEvents m_intHasAlert As
System.Web.UI.WebControls.TextBox
Public mMessageid As Integer
Public AlertType As Integer '1=header 2=Thread 3=Response
Public intHasAlert As Boolean 'Records weather there is an alert
on that message or not
Public intMessageID As Integer 'This should he the ID of the
message that you are watching.
Public Shared intCounter As Integer ' Counts the number of
controls that have been instanciated

#Region " Web Form Designer Generated Code "
'This call is required by the Web Form Designer.
<System.Diagnostics.DebuggerStepThrough()> Private Sub
InitializeComponent()
End Sub

'NOTE: The following placeholder declaration is required by the
Web Form Designer.
'Do not delete or move it.
Private designerPlaceholderDeclaration As System.Object

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
intCounter = intCounter + 1

If Not IsPostBack Then
If intHasAlert And (intMessageID <> 0) Then
imgAlert.ImageUrl = "../../image/AlertON.gif"
Else
imgAlert.ImageUrl = "../../image/AlertOFF.gif"
End If
If intMessageID > 0 Then
m_MessageID.Text = intMessageID
m_intHasAlert.Text = intHasAlert
End If
End If
End Sub

====================== ASPX web form
================================================== ==
-------- ASPX code -----------

<%@ Page Language="vb" enableViewState="false" AutoEventWireup="false"
Codebehind="WebForm1.aspx.vb" Inherits="wcBulletinBoard.WebForm1"
trace="false"%>
<%@ Register TagPrefix="MyControls" TagName="Header"
Src="Control/Header.ascx" %>
<%@ Register TagPrefix="MyControls" TagName="Alert"
Src="Control/AlertButton.ascx" %>
<%@ Register TagPrefix="MyControls" TagName="Footer"
Src="Control/Footer.ascx" %>
<form id="Form1" method="post" runat="server">
<MYCONTROLS:HEADER RUNAT="server" ID="Header2" NAME="Header1" />
<asp:datagrid id="dgrdHeaders" runat="server" width="100%"
GridLines="None" AllowPaging="True" PAGERSTYLE-VISIBLE="False"
AutoGenerateColumns="False" EditItemIndex="123" BorderStyle="None">
<HEADERSTYLE FORECOLOR="White" CSSCLASS="title"
BACKCOLOR="#003366"></HEADERSTYLE>
<COLUMNS>
<asp:BoundColumn
Visible="False"
READONLY="True"
DataField="intAlert" ></asp:BoundColumn>
<asp:BoundColumn
DataField="dTimeStamp"
ReadOnly="True"
HeaderText="Date and Time">
<HEADERSTYLE WIDTH="90" Wrap="False" ></HEADERSTYLE>
<ITEMSTYLE
HorizontalAlign="Left"
VerticalAlign="Top"
CssClass="txt"
Wrap="False" ></ITEMSTYLE></asp:BoundColumn>
<asp:TemplateColumn HeaderText="Alert">
<HEADERSTYLE Wrap="False"></HEADERSTYLE>
<ItemTemplate>
<asp:CheckBox id="chkintAlert"
AutoPostBack="True"
TextAlign="Right"
runat="server"
checked='<%#Container.DataItem("intAlert")%>'/>
<asp:textbox runat="server" id="txtTemp"
text='<%#Container.DataItem("intHeaderPK")%>'></asp:textbox>
<MyControls:Alert
runat="server"
AlertType="0"
intHasAlert='<%#Container.DataItem("intAlert")%>'
intMessageID='<%#Container.DataItem("intHeaderPK") %>'/>
</ItemTemplate>
<ItemStyle
CssClass="txt"
HorizontalAlign="Center"
VerticalAlign="Top"></ItemStyle></asp:TemplateColumn>
<asp:HyperLinkColumn
DataNavigateUrlField="intHeaderPK"
DataNavigateUrlFormatString="ThreadPage.aspx?Heade rFK={0}"
DataTextField="vchTitle" HeaderText="Title">
<ITEMSTYLE
HorizontalAlign="Left"
VerticalAlign="Top"
Wrap="true"
width="100%"></ITEMSTYLE></asp:HyperLinkColumn>
<asp:BoundColumn
DataField="vchAuthorName"
HeaderText="Author">
<HEADERSTYLE Wrap="False" WIDTH="55px"></HEADERSTYLE>
<ItemStyle HorizontalAlign="Left"
VerticalAlign="Top"
CssClass="txt"></ItemStyle></asp:BoundColumn>
<asp:BoundColumn DataField="intThreadCount"
HeaderText="Threads">
<HEADERSTYLE Wrap="False" ></HEADERSTYLE>
<ItemStyle
CssClass="txt"
HorizontalAlign="Center"
VerticalAlign="Top" ></ItemStyle></asp:BoundColumn>
</COLUMNS>
<PAGERSTYLE NEXTPAGETEXT="next" PREVPAGETEXT="prev"
HORIZONTALALIGN="Center"></PAGERSTYLE></asp:datagrid></TD>
<td vAlign="top" rowspan="2">
<table cellpadding="0" cellspacing="0" border="0" width="100%"
style="BORDER-BOTTOM: #000066 1px solid">
<tr><td align=right>
<asp:datagrid id="dgrdLatestLoggedOn" runat="server"
GridLines="None" Width="190" AutoGenerateColumns="False"
CssClass="txt" BorderStyle="None" PageSize="5">
<HEADERSTYLE FORECOLOR="White" CSSCLASS="title"
BACKCOLOR="#003366" Wrap="False"></HEADERSTYLE>
<COLUMNS>
<asp:BoundColumn DataField="vchAuthorName"
HeaderText="&nbsp;Recent Users">
<ItemStyle Wrap="False" ></ItemStyle></asp:BoundColumn>
<asp:BoundColumn DataField="dTimeStamp" >
<ItemStyle Wrap="False"
HorizontalAlign="right"></ItemStyle></asp:BoundColumn></COLUMNS>
<PAGERSTYLE NEXTPAGETEXT="next" PREVPAGETEXT="prev"
HORIZONTALALIGN="Center"></PAGERSTYLE></asp:datagrid></td></tr></table></TD></TR>
</TD></TR>

</TABLE>
</table>
</form>
-------------------------- code behind aspx ----------------------
Public Class WebForm1
Inherits System.Web.UI.Page
Protected WithEvents dgrdHeaders As
System.Web.UI.WebControls.DataGrid
Protected WithEvents dgrdLatestLoggedOn As
System.Web.UI.WebControls.DataGrid
Protected WithEvents lblLoggedOn As
System.Web.UI.WebControls.Label
Protected WithEvents Label1 As System.Web.UI.WebControls.Label
Protected WithEvents Label2 As System.Web.UI.WebControls.Label
Protected WithEvents btnAdmin As System.Web.UI.WebControls.Button
Protected WithEvents Form1 As System.Web.UI.HtmlControls.HtmlForm
Protected WithEvents lblCurrentPage As
System.Web.UI.WebControls.Label
Protected WithEvents lblOf As System.Web.UI.WebControls.Label
Protected WithEvents lblPageCount As
System.Web.UI.WebControls.Label
Protected WithEvents lnkNext As
System.Web.UI.WebControls.LinkButton
Protected WithEvents ibtnAlertNewHeader As
System.Web.UI.WebControls.ImageButton
Protected WithEvents lnkPrev As
System.Web.UI.WebControls.LinkButton
Protected WithEvents ws As localhost.Service1
Public Shared intWebform1PageCounter As Integer

#Region " Web Form Designer Generated Code "

'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
'====== TEST CODE ===========
intWebform1PageCounter = intWebform1PageCounter + 1
'====== END TEST CODE ===========
If Session("AuthorID") > 0 Then
ws = New localhost.Service1
ws.Credentials =
System.Net.CredentialCache.DefaultCredentials

dgrdHeaders.DataSource =
ws.SelectHeader(Session("dAuthorLastLogon"), Session("AuthorID"))
dgrdLatestLoggedOn.DataSource = ws.SelectLatestLoggedOn()

dgrdHeaders.DataBind()

dgrdLatestLoggedOn.DataBind()

Dim ds As DataSet
ds = ws.SelectAlertNewHeader(Session("AuthorID"))

If ds.Tables(0).Rows(0).Item(0) > 0 Then
ibtnAlertNewHeader.ImageUrl = "../image/AlertON.gif"
Else
ibtnAlertNewHeader.ImageUrl = "../image/AlertOFF.gif"
End If
Session("HeaderFK") = 0
If dgrdHeaders.PageCount = 1 Then
lblPageCount.Text = "1"
lnkNext.Visible = False
lnkPrev.Visible = False
Else
lblPageCount.Text = dgrdHeaders.PageCount
End If
Else
Response.Redirect("logon.aspx")
End If
End Sub
Public Sub NavigationLink_click(ByVal sender As System.Object,
ByVal e As CommandEventArgs)
If sender.commandname = "Prev" Then
If dgrdHeaders.CurrentPageIndex <> 0 Then
dgrdHeaders.CurrentPageIndex =
dgrdHeaders.CurrentPageIndex - 1
lblCurrentPage.Text = dgrdHeaders.CurrentPageIndex + 1
lnkNext.Visible = True
If lblCurrentPage.Text = 1 Then
lnkPrev.Visible = False
End If
End If
ElseIf sender.commandname = "Next" Then
If dgrdHeaders.CurrentPageIndex <> dgrdHeaders.PageCount -
1 Then
dgrdHeaders.CurrentPageIndex =
dgrdHeaders.CurrentPageIndex + 1
lblCurrentPage.Text = dgrdHeaders.CurrentPageIndex + 1
If lblCurrentPage.Text = dgrdHeaders.PageCount Then
lnkNext.Visible = False
lnkPrev.Visible = True
Else
lnkNext.Visible = True
lnkPrev.Visible = True
End If
End If
End If
dgrdHeaders.DataBind()
End Sub
Private Sub dgrdLatestLoggedOn_PageIndexChanged(ByVal source As
Object, ByVal e As System.Web.UI.WebControls.DataGridPageChangedEvent Args)
Handles dgrdLatestLoggedOn.PageIndexChanged
dgrdLatestLoggedOn.CurrentPageIndex = e.NewPageIndex
dgrdLatestLoggedOn.DataBind()
End Sub
Private Sub btnAdmin_Click(ByVal sender As System.Object, ByVal e
As System.EventArgs) Handles btnAdmin.Click
Response.Redirect("AuthorAdmin.aspx")
End Sub
Private Sub ibtnAlertNewHeader_Click(ByVal sender As Object, ByVal
e As System.Web.UI.ImageClickEventArgs) Handles
ibtnAlertNewHeader.Click
ws = New localhost.Service1
ws.Credentials = System.Net.CredentialCache.DefaultCredentials
If ibtnAlertNewHeader.ImageUrl = "../image/AlertON.gif" Then
ws.AddDelAlert(localhost.enumAlert.NewHeader, False,
Session("AuthorID"), 0)
ibtnAlertNewHeader.ImageUrl = "../image/AlertOFF.gif"
Else
ws.AddDelAlert(localhost.enumAlert.NewHeader, True,
Session("AuthorID"), 0)
ibtnAlertNewHeader.ImageUrl = "../image/AlertOFF.gif"
End If
Response.Redirect("webform1.aspx")
End Sub
Nov 17 '05 #1
0 1904

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Richard Payne | last post by:
I am developing a web application that utilises multiple grids, panels, validation controls etc on the same page. I have added the appropriate code to pop up dialogs to confirm delete in...
2
by: Tolga | last post by:
How do insert a user control i have created into a datagrid cell. Basically i am trying to create a column of my user controls. This is what i have tried so far. int i = 0; while (i <...
0
by: Jason | last post by:
I am pretty new to C# so bare with me... The design of my website utilizes tables on every page that look almost identical, save the data they are displaying. I have written the code to create...
5
by: sdbranum | last post by:
I have been using Visual C#.NET to code a large project having many data adapters, data sets, datagrids, multiple forms with tab pages, each containing various controls (mostly label, text boxes,...
0
by: Zi | last post by:
I have a user control within a data grid. I am binding the user control to one of the values from the data grid. The data grid implements paging. It is all working ok for the first page but once i...
6
by: Glenn Owens | last post by:
I have an ASP.Net page on which there are serveral static controls (listboxes, radiobuttonlist and textboxes). These controls are used to create criteria from which the code-behind will dynamically...
4
by: DotNetJunkies User | last post by:
I have created a User Control (a Pareto Chart) using C#. It works great in .Net Windows Apps, but I also need to use it in a Web Application (to view in IE). Everything I read on this seems to be...
1
by: thegame | last post by:
Filling One DataGrid Based on Selection from Another DataGrid - Both in Separate User Controls Hello, I have an interesting dilemma. I have an ASPX page with two user controls (two ASCXs). ...
2
by: tshad | last post by:
User VS 2003, I would like to use User Controls to control the page look with 3 User Controls (...PageTop.ascx, ...NavigateTop.ascx and PageBottom.ascx). I would put the Content User control...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.