473,597 Members | 2,174 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

DataList woes

I have a dataset that is made up of info from 2 tables. I have created a
relationship between these 2 and have added it to the dataset.

My datalist is working perfectly minus one little problem, the very last
field in my itemtemplate is an ID field from the child table. I would like
to display the Name of the company as opposed to the ID. Is there a way to
do this? I have read that there is a method called GetChildRows, but I am
unsure if this is what I need. How can I show the name instead?

Thank you, Lerp
Nov 18 '05 #1
4 1178
On the itemdatabound event you should just look up the information in the
child table and plug it into the control.

"Lerp" <ad***@officien ce.ca> wrote in message
news:ev******** ******@TK2MSFTN GP09.phx.gbl...
I have a dataset that is made up of info from 2 tables. I have created a
relationship between these 2 and have added it to the dataset.

My datalist is working perfectly minus one little problem, the very last
field in my itemtemplate is an ID field from the child table. I would like
to display the Name of the company as opposed to the ID. Is there a way to do this? I have read that there is a method called GetChildRows, but I am
unsure if this is what I need. How can I show the name instead?

Thank you, Lerp

Nov 18 '05 #2
It isn't clear but it sounds like you need to do one of two things. If
you're already showing the ID column, it's trivial to change to the company
name column if both columns are in the same table. If they are in two
different tables and you're already displaying the company ID from the
child, you would want to use GetParentRow.

Post some sample code or more information.
Dale

"Lerp" <ad***@officien ce.ca> wrote in message
news:ev******** ******@TK2MSFTN GP09.phx.gbl...
I have a dataset that is made up of info from 2 tables. I have created a
relationship between these 2 and have added it to the dataset.

My datalist is working perfectly minus one little problem, the very last
field in my itemtemplate is an ID field from the child table. I would like
to display the Name of the company as opposed to the ID. Is there a way to do this? I have read that there is a method called GetChildRows, but I am
unsure if this is what I need. How can I show the name instead?

Thank you, Lerp

Nov 18 '05 #3
Thx guys for replying, I tried getting my sub to show the client full name
Rick, but had trouble getting the value.

I appreciate you help guys I really do.
Dale the client's full name is is the CLIENT table and I have a clientid in
the BOOKING table. My datalist is displaying fine, except I am unsure how
to get at the 'Parent Info' syntax wise.

I also thought that I might be able to easily access this data via the
datarelation but had difficulty doing that as well.
I know I am close, but here goes:


<%@ Page Language="VB" ContentType="te xt/html" ResponseEncodin g="iso-8859-1"
debug="true" %>
<%@ Import Namespace="Syst em.Data" %>
<%@ Import Namespace="Syst em.Data.SQLClie nt" %>
<script language="vb" runat="server">
Dim curAgentID as Integer
Dim curAgencyID as Integer
Dim curAgencyName as String
Dim curAgentName as String
Dim PageTitle as String
Dim curSecLevel as String
Dim curGroupID as Integer
Dim curStatus as String
Dim strSQLa as String
Dim strSQLb as String
Dim strSQLc as String
Dim ds as DataSet = New DataSet()

curAgentID = Session("sesemp Id")
curAgencyID = Session("sesemp Agencyid")
curAgencyName = Session("sesemp Agencyname")
PageTitle = "Agency Bookings"
curSecLevel = Session("sesemp Security")
curGroupID = Session("sesemp Groupid")

'AGENT BOOKINGS QUERY
strSQLa = "SELECT bookingid, clientid, agencyid, empid, arn,
bookingdatetime stamp, status FROM BOOKING WHERE agencyid =" & curAgencyID &
" AND empid=" & curAgentID & " AND status = 'Draft'"
'CLIENT NAME QUERY
strSQLb = "SELECT clientid, fname, lname FROM CLIENT WHERE agencyid=" &
curAgencyID
'EMPLOYEE NAME QUERY
strSQLc = "SELECT empid, fname, lname FROM EMPLOYEE WHERE agencyid =" &
curAgencyID
'FILL BOOKINGS
Dim MyConn as New SQLConnection(C onfigurationSet tings.AppSettin gs("dbConn"))
Dim myCmd as New SqlDataAdapter( strSQLa, MyConn)
myCmd.fill(ds, "BOOKING")

'FILL CLIENTS
Dim myCmdb as New SqlDataAdapter( strSQLb, MyConn)
myCmdb.fill(ds, "CLIENT")

'FILL EMPLOYEES
Dim myCmdc as New SqlDataAdapter( strSQLc, MyConn)
myCmdc.fill(ds, "EMPLOYEE")
'response.write (ds.Tables(0).R ows.Count)
'response.write (curAgencyID)

'IF THERE ARENT ANY CLIENTS WITH BOOKINGS DO NOT DISPLAY !!!! SIMPLE MESSAGE
TO USER HERE STATING NO BOOKINGS IE: PANEL
IF ds.Tables(1).Ro ws.Count > 0 THEN
'SET UP TABLE RELATIONS HERE
Dim datrela as New DataRelation("C lientBookings",
ds.Tables("CLIE NT").Columns("c lientid"),
ds.Tables("BOOK ING").Columns(" clientid"))
'add relation to collection
ds.Relations.Ad d(datrela)

Dim datrelb as New DataRelation("E mployeeBookings ",
ds.Tables("EMPL OYEE").Columns( "empid"),
ds.Tables("BOOK ING").Columns(" empid"))
'add relation to collection
ds.Relations.Ad d(datrelb)


bookingspanel.v isible = true
nobookingspanel .visible = false
'BIND DATA TO DATALIST
dlBookings.Data Source = ds
dlBookings.Data Bind()
myConn.close
mylabel.Text = ds.Tables(0).Ro ws.Count
mylabel.visible = true

ELSE
'SET LABEL MESSAGE HERE - NO BOOKINGS CURRENTLY, ETC...
mylabel.Text = "0"
mylabel.visible = true
bookingspanel.v isible = false
nobookingspanel .visible = true

END IF

END SUB


'THIS SUB HANDLES GRABBING CLIENT AND EMPLOYEE NAMES (for now only
clientnames)
Sub dlBookings_OnIt emDataBound(sen der As Object, e As DataListItemEve ntArgs)

If e.Item.ItemType = ListItemType.It em Or e.Item.ItemType =
ListItemType.Al ternatingItem Then

' Retrieve the Label control in the current DataListItem.
Dim ClientNameLabel As Label = e.Item.FindCont rol("clientname label")
Dim curClientID as Integer = e.item.FindCont rol("clientid") .Text

' GRAB client name using ID from db here
Dim clientlabel As String
Dim strSQL as String
'SQL STATEMENT
strSQL = "SELECT fullname FROM CLIENT WHERE clientid=" & curClientID
'NEW CONNECTION OBJECT
Dim MyConn as New
SQLConnection(C onfigurationSet tings.AppSettin gs("dbConn"))

'NEW DATAREADER
Dim objDR as SQLDataReader

'NEW COMMAND OBJECT
Dim Cmd as New SQLCommand(strS QL, MyConn)

'OPEN CONNECTION
MyConn.Open()

'EXECUTE QUERY AND RETRIEVE DATA INTO READER
objDR = Cmd.ExecuteRead er(system.data. CommandBehavior .CloseConnectio n)
WHILE objDR.Read
clientlabel = objDR("fullname ")
END While

myConn.close

'redisplay it in the DataList.
ClientNameLabel .Text = clientlabel.ToS tring()

End If

End Sub



</script>

<html>
<head>
<title>AgentSho pper</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<link href="css/todd.css" rel="stylesheet " type="text/css">

<!-- #include file="topsec.as px" -->
<!--- START OF BOOKINGS PANEL--->
<form runat="server">

<table width="790" border="0" cellpadding="0" cellspacing="0" >
<tr valign="top">
<td align="left" colspan="5" class="title">< %= Session("sesemp Fname") & " "
& Session("sesemp Lname")%>'s Draft Bookings - <asp:Label ID="mylabel"
runat="server"/></td>
</tr>
<tr height="15">
<td align="left" colspan="5"></td>
</tr>
<asp:panel ID="bookingspan el" runat="server">
<asp:DataList id="dlBookings "
runat="server"
cellpadding="3"
cellspacing="3"
GridLines="Both "
borderstyle="no ne"
backcolor="#FFF FFF"
width="790px"
headerstyle-font-name="Verdana"
headerstyle-font-size="13pt"
headerstyle-horizontalalign ="left"
headerstyle-font-bold="TRUE"
itemstyle-backcolor="#FFF FFF"
itemstyle-forecolor="#000 000"
alternatingitem style-backcolor="#C6E FF7"
alternatingitem style-forecolor="#FFF FFF"
footerstyle-font-size="9pt"
footerstyle-font-italic="true"
OnItemDataBound ="dlBookings_On ItemDataBound">

<HeaderTemplate >
<tr valign="top" bgcolor="#CCCCC C">
<td align="left" class="textbox" >Agent Reference Number</td>
<td align="left" class="textbox" >Status</td>
<td align="left" class="textbox" >Booking Date</td>
<td align="left" class="textbox" >Agent</td>
<td align="left" class="textbox" >Client</td>
</tr>
</HeaderTemplate>

<ItemTemplate >
<tr valign="top">
<td align="left" class="textbox" ><%#Container.D ataItem("arn")% ></td>
<td align="left" class="textbox" ><%#Container.D ataItem("status ")%></td>
<td align="left"
class="textbox" ><%#Container.D ataItem("bookin gdatetimestamp" )%></td>
<td align="left" class="textbox" ></td>
<td align="left" class="textbox" ><asp:Label id="clientnamel abel"
runat="server"/></td>
</tr>
</ItemTemplate>
<AlternatingIte mTemplate>
<tr valign="top">
<td align="left" class="textbox" ><%#Container.D ataItem("arn")% ></td>
<td align="left" class="textbox" ><%#Container.D ataItem("status ")%></td>
<td align="left"
class="textbox" ><%#Container.D ataItem("bookin gdatetimestamp" )%></td>
<td align="left" class="textbox" ></td>
<td align="left" class="textbox" ><asp:Label id="clientnamel abel"
runat="server"/></td>
</tr>
</AlternatingItem Template>

<FooterTemplate >
<tr height="25">
<td align="left" colspan="5"></td>
</tr>
<tr valign="top">
<td align="left" colspan="5" class="textbox" ></td>
</tr>
</table>
</FooterTemplate>

</asp:DataList>

<!--- END OF BOOKINGS PANEL --->
</asp:panel>


<!--- START OF NOBOOKINGS PANEL--->
<asp:panel ID="nobookingsp anel" runat="server">
<tr valign="top">
<td align="left" class="bodycopy ">

<table width="790" cellpadding="5" cellspacing="0" border="0"
bordercolor="#C CCCCC">
<tr valign="top">
<td align="left" class="textbox" ><%= Session("sesemp Fname") & " " &
Session("sesemp Lname")%> has 0 draft bookings currently.</td>
</tr>
</table>

</td>

</tr>
<!--- END OF NOBOOKINGS PANEL --->
</asp:panel>
</form>


"DalePres" <no****@nomail. com> wrote in message
news:eb******** ******@TK2MSFTN GP12.phx.gbl...
It isn't clear but it sounds like you need to do one of two things. If
you're already showing the ID column, it's trivial to change to the company name column if both columns are in the same table. If they are in two
different tables and you're already displaying the company ID from the
child, you would want to use GetParentRow.

Post some sample code or more information.
Dale

"Lerp" <ad***@officien ce.ca> wrote in message
news:ev******** ******@TK2MSFTN GP09.phx.gbl...
I have a dataset that is made up of info from 2 tables. I have created a
relationship between these 2 and have added it to the dataset.

My datalist is working perfectly minus one little problem, the very last
field in my itemtemplate is an ID field from the child table. I would like to display the Name of the company as opposed to the ID. Is there a way

to
do this? I have read that there is a method called GetChildRows, but I am unsure if this is what I need. How can I show the name instead?

Thank you, Lerp


Nov 18 '05 #4
If your ID is unique, why not just do a select against your other table
instead of trying to work through the relation?

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 18 '05 #5

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

Similar topics

1
1761
by: pete K | last post by:
Is it possible in asp.net to have a datalist in the itemtemplate of another datalist? For example: <asp:datalist id="MyList" runat="server"> <ItemTemplate> <table border="0" width="300"> <tr> <td><%# DataBinder.Eval(Container.DataItem, "title") %></td>
10
2835
by: Bharat | last post by:
Hi Folks, Suppose I have two link button on a page (say lnkBtn1 and lnkBtn2). On the click event of the lnkbtn1 I have to add a dynamically created control. And On the click event of the lnkBtn2 I have to add a datalist control. Using this datalist control I should be able to add edit, modify and cancel the items listed in this control. Here is how I designed. I used placeholder to add the controls dynamically to the page on the click...
4
4033
by: Patrick.O.Ige | last post by:
I have a CheckBoxList in a DataList and i'm trying to get item Selected after doing a postBack. I have set my CheckBoxlist AutoPostBack="True" Any ideas what 'm doing wrong? It seems not to work:( Thanks My CheckBoxList in the DataList Below
6
9573
by: Paul | last post by:
I am trying to use a DataList and the ItemTemplate. I am binding the Datalist to a SQL query that gives me a list of Items with a Parent Category. I want to loop through all the items, but only print the Parent Category once, regardless of how many child items are in it. So my perfect output would look something like:
2
3431
by: Hans Merkl | last post by:
Hi, I am trying to use a user control as EditItemTemplate in a DataList. It loads fine but I can't figure out how to bind to the data of the DataList. Here is what I have got so far: //Page_load of my user control protected void Page_Load(object sender, EventArgs e) { IDataItemContainer DataContainer = this.Parent as
3
10288
by: Mirek Endys | last post by:
I have DataList as part of DataList item. DataList in DataList. The parent DataList working well including Edit command, that shows Edit template and correctly bind the data into edit template (where is the child DataList).... But in case I want to make Edit in this child DataList it is not working... No edit template showed... :( this is a code that i use for the child DataList... Edit command // this is for child DataList...
0
1641
by: Les Caudle | last post by:
I have a menu system composed of a DataList nested inside a DataList. The outer DataList has it's DataSource (composed of a DataSet with two tables linked by a CategoryPagesRelation Relation) set in the Page_Load. The inner DataList has its DataSource set in the ascx file as: <asp:DataList ID="PageList" runat="server" CellPadding="3" CellSpacing="0" DataSource='<%#...
1
2656
by: AJ | last post by:
Hi all, With the following code in mind : <asp:DataList ID="dlOne" DataKeyField="myField1" DataSource="<%# GetDataSource1()" Runat="server"> <ItemTemplate> Output Value Here! <asp:DataList ID="dlTwo" DataKeyField="myField2" DataSource="<%# GetDataSource2(?,?)" Runat="server">
3
2803
by: Crazy Cat | last post by:
Hi all, I am developing an asp.net 2.0 application in Visual Studio 2005. On my page I have a simple datalist that is bound programmatically to a collection of simple objects. On this page I need to control the visibility of a textbox based on a dropdown selection in the datalist's edititem template. To do this, I registered a client script block function and attached a client side handler for the dropdownlist's onchange event in the...
0
7962
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
7884
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8267
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8380
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8258
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
6681
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5423
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
1
2394
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
0
1229
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.