Datagrid > DataList problem - Any clues?

B

Brock

Thanks in advance... (you can see a screenshot of what my form looks
like currently at http://www.juggernautical.com/DataGrid.jpg - the
Datalist is super-imposed in 'design view' but the DataGrid is the
actual running of the page) I've almost got this working (?) but need
a little help. I have an .aspx page that has a DataGrid listing
employees with a "Select" button that is to be used to populate the
DataList to the right of the DataGrid with additional employee
information. I'm basing this off the model found at
http://www.aspnet101.com/aspnet101/aspnet/codesample.aspx?code=choose
.. this is a very good example of what I'm trying to do. I can populate
the DataGrid with no problem, but the "Select" button will not
populate the DataList. BTW, I'm using framework 1.1 and Code behind
(all listed below), in addition I'm using Broker DLL's to get my data.
Any clues?

<%@ Page Language="vb" AutoEventWireup="false"
Codebehind="MainDepartment.aspx.vb"
Inherits="Forsyth.HR_ReportingTool.UI.MainDepartment" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<title>MainDepartment</title>
<META http-equiv="Content-Type" content="text/html;
charset=windows-1252">
<meta content="False" name="vs_snapToGrid">
<meta content="False" name="vs_showGrid">
<meta content="Microsoft Visual Studio .NET 7.1" name="GENERATOR">
<meta content="Visual Basic .NET 7.1" name="CODE_LANGUAGE">
<meta content="JavaScript" name="vs_defaultClientScript">
<meta content="http://schemas.microsoft.com/intellisense/ie5"
name="vs_targetSchema">
</HEAD>
<BODY background="file:///C:\Inetpub\wwwroot\HR_ReportingTool
\vignette.gif">
<div style="PADDING-RIGHT: 10px; PADDING-LEFT: 10px; FONT-SIZE:
medium; BORDER-LEFT-COLOR: white; LEFT: 50px; FLOAT: none; BORDER-
BOTTOM-COLOR: white; MARGIN-LEFT: 20px; OVERFLOW: auto; WIDTH: 734px;
CLIP: rect(auto auto auto auto); COLOR: black; BORDER-TOP-STYLE:
inset; BORDER-TOP-COLOR: white; TEXT-INDENT: 5%; FONT-FAMILY: 'Times
New Roman'; BORDER-RIGHT-STYLE: inset; BORDER-LEFT-STYLE: inset;
POSITION: absolute; TOP: 50px; HEIGHT: 599px; BACKGROUND-COLOR: white;
TEXT-ALIGN: left; BORDER-RIGHT-COLOR: white; BORDER-BOTTOM-STYLE:
inset"
align="left">
<DIV style="POSITION: absolute">
<FORM id="Form1" method="post" runat="server">
<asp:datagrid id="dgEmployees" runat="server" Font-Size="X-Small"
BorderColor="Silver" AllowSorting="True"
HorizontalAlign="Center" BorderStyle="Solid" Height="136px"
Width="640px">
<SelectedItemStyle Font-Underline="True" Font-Bold="True"></
SelectedItemStyle>
<AlternatingItemStyle BackColor="#C0FFC0"></
AlternatingItemStyle>
<Columns>
<asp:TemplateColumn>
<ItemTemplate>
<asp:LinkButton id="Select" Text="Details"
CommandName="ShowDetails" runat="server" />
</ItemTemplate>
</asp:TemplateColumn>
</Columns>
</asp:datagrid></FORM>
</DIV>
</div>
<div style="PADDING-RIGHT: 10px; PADDING-LEFT: 10px; FONT-SIZE:
medium; BORDER-LEFT-COLOR: white; LEFT: 869px; FLOAT: none; BORDER-
BOTTOM-COLOR: white; MARGIN-LEFT: 20px; OVERFLOW: auto; WIDTH: 277px;
CLIP: rect(auto auto auto auto); COLOR: black; BORDER-TOP-STYLE:
inset; BORDER-TOP-COLOR: white; TEXT-INDENT: 5%; FONT-FAMILY: 'Times
New Roman'; BORDER-RIGHT-STYLE: inset; BORDER-LEFT-STYLE: inset;
POSITION: absolute; TOP: 50px; HEIGHT: 598px; BACKGROUND-COLOR:
#c0ffc0; TEXT-ALIGN: left; BORDER-RIGHT-COLOR: white; BORDER-BOTTOM-
STYLE: inset"
align="left"><asp:datalist id="dlDetails" runat="server" Font-
Size="X-Small" BorderColor="Silver" Height="350px"
Width="309px" RepeatLayout="Flow">
<ItemTemplate>
<B>Emp #: </B>
<%# Container.DataItem("Key") %>
<br>
<B>First Name: </B>
<%# Container.DataItem("FirstName") %>
<br>
<B>MI: </B>
<%# Container.DataItem("MI") %>
<br>
<B>Last name: </B>
<%# Container.DataItem("LastName") %>
<br>
<B>Nick Name: </B>
<%# Container.DataItem("NickName") %>
<br>
<B>Use Nick Name Only: </B>
<%# Container.DataItem("UseNickNameOnly") %>
<br>
<B>DOB: </B>
<%# Container.DataItem("DOBString") %>
<br>
<B>Start Date String: </B>
<%# Container.DataItem("StartDateString") %>
<br>
<B>Longevity Date: </B>
<%# Container.DataItem("LongevityDate") %>
<br>
<B>Gender: </B>
<%# Container.DataItem("Gender") %>
<br>
<B>Race: </B>
<%# Container.DataItem("Race") %>
<br>
<B>Status: </B>
<%# Container.DataItem("Status") %>
<br>
<B>Email Address: </B>
<%# Container.DataItem("EmailAddress") %>
<br>
<B>Login Name: </B>
<%# Container.DataItem("LoginName") %>
<br>
<B>Home Phone: </B>
<%# Container.DataItem("HomePhoneFormatted") %>
<br>
<B>Payroll Employee ID: </B>
<%# Container.DataItem("PayrollEmployeeID") %>
<br>
<B>Retiree: </B>
<%# Container.DataItem("Retiree") %>
<br>
<B>Retirement Number: </B>
<%# Container.DataItem("RetirementNumber") %>
<br>
<B>Service Date String: </B>
<%# Container.DataItem("ServiceDateString") %>
<br>
<B>Suffix: </B>
<%# Container.DataItem("Sfx") %>
<br>
<B>Advance Leave: </B>
<%# Container.DataItem("AdvanceLeave") %>
<br>
<B>Benefits: </B>
<%# Container.DataItem("Benefits") %>
<br>
<B>Cobra: </B>
<%# Container.DataItem("Cobra") %>
<br>
<B>Evaluation Due: </B>
<%# Container.DataItem("EvaluationDueString") %>
<br>
<B>Law Sep: </B>
<%# Container.DataItem("LawSep") %>
<br>
<B>LOA: </B>
<%# Container.DataItem("LOA") %>
<br>
<B>Added By: </B>
<%# Container.DataItem("AddedBy") %>
<br>
<B>Added By Name: </B>
<%# Container.DataItem("AddedByName") %>
<br>
<B>Added Date: </B>
<%# Container.DataItem("AddedDateString") %>
<br>
<B>Ad Username: </B>
<%# Container.DataItem("AdUsername") %>
<br>
<B>Updated By: </B>
<%# Container.DataItem("UpdatedBy") %>
<br>
<B>Updated By Name: </B>
<%# Container.DataItem("UpdatedByName") %>
<br>
<B>Updated Date String: </B>
<%# Container.DataItem("UpdatedDateString") %>
<br>
</ItemTemplate>
</asp:datalist></div>
</BODY>
</HTML>

Code-Behind:

Public Class MainDepartment
Inherits System.Web.UI.Page

Private m_department As String
Private m_title As String

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
'lblWelcome.Text = "Hello " & Global.UserSecurity.Fname.Trim &
" " & Global.UserSecurity.Lname
Dim act As Action
Dim pos As Position
Dim empname As String
Dim lvi As ListItem
Dim Employee As Employee
Dim empcount As Integer
act = (New
ActionBroker).GetActionCurrent(Global.UserSecurity.EmpId, Today,
Global.UserName, Global.UserPassword, Global.appDataSource)
pos = (New PositionBroker).GetPosition(act.PositionID,
Global.UserName, Global.UserPassword, Global.appDataSource)
m_department = pos.Department.Name
Dim emps As Employees = (New
EmployeeBroker).GetCurrentEmployeesByDepartment(m_department,
Global.UserName, Global.UserPassword, Global.appDataSource)
Dim dt As New DataTable
Dim count As Integer = 0
For Each emp As Employee In emps
SetListViewItem(emp, dt, count)
count = count + 1
Next
dgEmployees.DataSource = dt
dgEmployees.DataBind()
End Sub

Private Sub ShowDetails(ByVal sender As Object, ByVal e As
DataGridCommandEventArgs)
?????????
?????????
End Sub

Private Sub SetListViewItem(ByVal dr As Employee, ByVal dt As
DataTable, ByVal count As Integer)
If count = 0 Then
dt.Columns.Add("Emp #")
dt.Columns.Add("Last Name")
dt.Columns.Add("First Name")
dt.Columns.Add("Title")
End If
Dim EmpPos As Action = (New
ActionBroker).GetActionCurrent(dr.Key, Today, Global.UserName,
Global.UserPassword, Global.appDataSource)
Dim employee As DataRow = dt.NewRow
employee("Emp #") = dr.Key
employee("Last Name") = dr.LastName

employee("First Name") = dr.FirstName
employee("Title") = EmpPos.WorkAgainstInfo.Title
dt.Rows.Add(employee)
End Sub 'SetListViewItem

Private Function FindEmp(ByVal EmployeeID As Integer) As String
Dim emp As Employee
Dim retval As String
Try
If EmployeeID > 0 Then
emp = (New EmployeeBroker).GetEmployee(EmployeeID,
Global.UserName, Global.UserPassword, Global.appDataSource)
retval = String.Empty
If Not IsNothing(emp) Then
retval = emp.FirstName & " " & emp.MI & " " &
emp.LastName
Else
retval = "Vacant"
End If
Else
retval = ""
End If
Catch ex As Exception
Global.HandleException(ex)
retval = String.Empty
End Try
Return retval
End Function

End Class
 
T

Teemu Keiski

Hi,

the code in Page_Load should be wrapped inside If Not Page.IsPostBack check
so that it's not databound on every request. Second is that I cannot see
ShowDetails method being wired to handle anything anywhere, and as you have
specified this in the grid:

<asp:LinkButton id="Select" Text="Details"
CommandName="ShowDetails" runat="server" />

I assume you want to populate DataList when this Button is clicked. Either
wire the ShowDetails method to Command event of datagrid
(OnCommand="ShowDetails)" when it is called when Button is clicked (and you
can check the CommandName if it macthes the expected one) or write
declaratively a click event handler of the Button directly.
 

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,968
Messages
2,570,153
Members
46,701
Latest member
XavierQ83

Latest Threads

Top