so close..I think

L

Lerp

Hi,

I have this sub in which I am trying to get a client name from a second
table based on a clientid value in my datalist. I am having problems
grabbing the clientid value out of my datalist and putting it into my
variable curClientID. How do you grab a value out of a datalist properly
please?

Thx,Lerp



Here's my sub:



'THIS SUB HANDLES GRABBING CLIENT NAMES
Sub dlBookings_OnItemDataBound(sender As Object, e As DataListItemEventArgs)

If e.Item.ItemType = ListItemType.Item Or e.Item.ItemType =
ListItemType.AlternatingItem Then

' Retrieve the Label control in the current DataListItem.
Dim ClientNameLabel As Label =
e.Item.FindControl("clientnamelabel")


'Trying to grab clientid here

********************************************
Dim curClientID
curClientID = e.item.FindControl("clientid")....

********************************************




' 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(ConfigurationSettings.AppSettings("dbConn"))

'NEW DATAREADER
Dim objDR as SQLDataReader

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

'OPEN CONNECTION
MyConn.Open()

'EXECUTE QUERY AND RETRIEVE DATA INTO READER
objDR = Cmd.ExecuteReader(system.data.CommandBehavior.CloseConnection)


WHILE objDR.Read
clientlabel = objDR("fullname")
END While

myConn.close

'redisplay it in the DataList.
clientnamelabel.Text = clientlabel

End If



End Sub
 
J

jm

Lerp said:
Hi,

I have this sub in which I am trying to get a client name from a second
table based on a clientid value in my datalist. I am having problems
grabbing the clientid value out of my datalist and putting it into my
variable curClientID. How do you grab a value out of a datalist properly
please?

Thx,Lerp
Here's my sub:



'THIS SUB HANDLES GRABBING CLIENT NAMES
Sub dlBookings_OnItemDataBound(sender As Object, e As DataListItemEventArgs)

If e.Item.ItemType = ListItemType.Item Or e.Item.ItemType =
ListItemType.AlternatingItem Then

' Retrieve the Label control in the current DataListItem.
Dim ClientNameLabel As Label =
e.Item.FindControl("clientnamelabel")


'Trying to grab clientid here

********************************************
Dim curClientID
curClientID = e.item.FindControl("clientid")....

********************************************




' 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(ConfigurationSettings.AppSettings("dbConn"))

'NEW DATAREADER
Dim objDR as SQLDataReader

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

'OPEN CONNECTION
MyConn.Open()

'EXECUTE QUERY AND RETRIEVE DATA INTO READER
objDR = Cmd.ExecuteReader(system.data.CommandBehavior.CloseConnection)


WHILE objDR.Read
clientlabel = objDR("fullname")
END While

myConn.close

'redisplay it in the DataList.
clientnamelabel.Text = clientlabel

End If



End Sub

If the curClientID is a label, can't you just get the .text of it? You only
told it to find the control. You did not access any of the properties
associated with it (unless there is something after the elipsis ...).
 
L

Lerp

Hi jm,

I am trying to display the client name on the label in the itemtemplate, but
first I have to read the clientid from the fourth field of the current row
being displayed, do a query based on that clientid, and assign the
clientname value to the label within the datalist loop. My problem is that
I am unsure how to grab the value for the fourth column of the current row
of the datalist loop. there is nothing after the elipsis. I am unsure what
to write in order to grab that column value. I am coming from asp
background into .net.

Cheers, Lerp
 
J

jm

Lerp said:
Hi jm,

I am trying to display the client name on the label in the itemtemplate, but
first I have to read the clientid from the fourth field of the current row
being displayed, do a query based on that clientid, and assign the
clientname value to the label within the datalist loop. My problem is that
I am unsure how to grab the value for the fourth column of the current row
of the datalist loop. there is nothing after the elipsis. I am unsure what
to write in order to grab that column value. I am coming from asp
background into .net.

Cheers, Lerp
Okay, first, just to let you know "ClientID" is a reserved word in .net for
getting the unique asp.net generated value for a given control; especially
useful in building javascript applications. It allows you to use the
objects on the client that asp.net generates a unique number for (like the
ctl1, etc. do a view source for an example.)

I believe you are using ClientID like OrderID and it looks like you want to
retrieve a value from a datalist that you generate (and is visible) and then
use that value for use in another query that those values are then sent to
the user.

Say you have a datagrid:

sub mysub(sender as Object, e as DataGridItemEventArgs)

CType(e.Items.Cells(0).Controls(0), Button).visible = false

so, in:

"Dim curClientID
put:

Dim curClientID as String = e.Items.Cells(?).Controls(?).label).text

to retrieve the value at that location. Use the type of control you have
and its associated methods and properties (like .text).

Look here for a great primer (I know you may not be using the datagrid, but
it will still help you.):

http://aspnet.4guysfromrolla.com/articles/071002-1.3.aspx

in here you will see an example close to what I have shown you. However,
you should go to the first part of the set of articles and start over:
http://aspnet.4guysfromrolla.com/articles/040502-1.aspx

However, it looks like to get your data for your first datalist that you are
sending to the client you have some SQL or data somewhere you are retrieving
to build the datalist in the first place. So, instead of printing out the
datalist first and then searching for the newly printed out value from your
new datalist, just get the value from the retrieved SQL results, save it a
variable and then use THAT value for your next query.

For example, assume that I just queried a database and retreived my results.
You could get a value at the proper point in your retrieval by:

dim curClientID as string =
datasource.tables(0).rows(0)("client_id").toString()

Then, use curClientID below in your next set of code.

I hope I understood your problem and that this somehow helps you (also, you
may also wish to avoid top posting for reading clarity.)

For a view of what I was saying about ClientID, see:


http://msdn.microsoft.com/library/d...frlrfSystemWebUIControlClassClientIDTopic.asp

Lerp said:
Hi jm,

I am trying to display the client name on the label in the itemtemplate, but
first I have to read the clientid from the fourth field of the current row
being displayed, do a query based on that clientid, and assign the
clientname value to the label within the datalist loop. My problem is that
I am unsure how to grab the value for the fourth column of the current row
of the datalist loop. there is nothing after the elipsis. I am unsure what
to write in order to grab that column value. I am coming from asp
background into .net.

Cheers, Lerp
Okay, first, just to let you know "ClientID" is a reserved word in .net for
getting the unique asp.net generated value for a given control; especially
useful in building javascript applications. It allows you to use the
objects on the client that asp.net generates a unique number for (like the
ctl1, etc. do a view source for an example.)

I believe you are using ClientID like OrderID and it looks like you want to
retrieve a value from a datalist that you generate (and is visible) and then
use that value for use in another query that those values are then sent to
the user.

Say you have a datagrid:

sub mysub(sender as Object, e as DataGridItemEventArgs)

CType(e.Items.Cells(0).Controls(0), Button).visible = false

so, in:

"Dim curClientID
put:

Dim curClientID as String = e.Items.Cells(?).Controls(?).label).text

to retrieve the value at that location. Use the type of control you have
and its associated methods and properties (like .text).

Look here for a great primer (I know you may not be using the datagrid, but
it will still help you.):

http://aspnet.4guysfromrolla.com/articles/071002-1.3.aspx

in here you will see an example close to what I have shown you. However,
you should go to the first part of the set of articles and start over:
http://aspnet.4guysfromrolla.com/articles/040502-1.aspx

However, it looks like to get your data for your first datalist that you are
sending to the client you have some SQL or data somewhere you are retrieving
to build the datalist in the first place. So, instead of printing out the
datalist first and then searching for the newly printed out value from your
new datalist, just get the value from the retrieved SQL results, save it a
variable and then use THAT value for your next query.

For example, assume that I just queried a database and retreived my results.
You could get a value at the proper point in your retrieval by:

dim curClientID as string =
datasource.tables(0).rows(0)("client_id").toString()

Then, use curClientID below in your next set of code.

I hope I understood your problem and that this somehow helps you (also, you
may also wish to avoid top posting for reading clarity.)

For a view of what I was saying about ClientID, see:


http://msdn.microsoft.com/library/d...frlrfSystemWebUIControlClassClientIDTopic.asp
 
L

Lerp

Thank you jm, I managed to get the name to display properly based on most
of your suggestions. Thank you again.

Thx, Lerp
 

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

No members online now.

Forum statistics

Threads
473,768
Messages
2,569,575
Members
45,053
Latest member
billing-software

Latest Threads

Top