so close..I think

Discussion in 'ASP .Net' started by Lerp, May 8, 2004.

  1. Lerp

    Lerp Guest

    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
     
    Lerp, May 8, 2004
    #1
    1. Advertising

  2. Lerp

    jm Guest

    "Lerp" <> wrote in message
    news:%23dwk$...
    > 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 ...).


    ---

    Checked by AVG anti-virus system (http://www.grisoft.com).
    Version: 6.0.677 / Virus Database: 439 - Release Date: 5/4/2004
     
    jm, May 8, 2004
    #2
    1. Advertising

  3. Lerp

    Lerp Guest

    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





    "jm" <> wrote in message
    news:BPanc.6774$z06.1276684@attbi_s01...
    >
    > "Lerp" <> wrote in message
    > news:%23dwk$...
    > > 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 ...).
    >
    >
    > ---
    >
    > Checked by AVG anti-virus system (http://www.grisoft.com).
    > Version: 6.0.677 / Virus Database: 439 - Release Date: 5/4/2004
    >
    >
     
    Lerp, May 8, 2004
    #3
  4. Lerp

    jm Guest

    "Lerp" <> wrote in message
    news:...
    > 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
    >
    >
    >
    >
    >
    > "jm" <> wrote in message
    > news:BPanc.6774$z06.1276684@attbi_s01...
    > >
    > > "Lerp" <> wrote in message
    > > news:%23dwk$...
    > > > 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 ...).
    > >
    > >
    > > ---
    > >
    > > Checked by AVG anti-virus system (http://www.grisoft.com).
    > > Version: 6.0.677 / Virus Database: 439 - Release Date: 5/4/2004
    > >

    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
    > > > curClientID = e.item.FindControl("clientid")...."


    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" <> wrote in message
    news:...
    > 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
    >
    >
    >
    >
    >
    > "jm" <> wrote in message
    > news:BPanc.6774$z06.1276684@attbi_s01...
    > >
    > > "Lerp" <> wrote in message
    > > news:%23dwk$...
    > > > 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 ...).
    > >
    > >
    > > ---
    > >
    > > Checked by AVG anti-virus system (http://www.grisoft.com).
    > > Version: 6.0.677 / Virus Database: 439 - Release Date: 5/4/2004
    > >

    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
    > > > curClientID = e.item.FindControl("clientid")...."


    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
     
    jm, May 9, 2004
    #4
  5. Lerp

    Lerp Guest

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

    Thx, Lerp


    "jm" <> wrote in message
    news:_%fnc.7930$536.1607804@attbi_s03...
    >
    > "Lerp" <> wrote in message
    > news:...
    > > 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
    > >
    > >
    > >
    > >
    > >
    > > "jm" <> wrote in message
    > > news:BPanc.6774$z06.1276684@attbi_s01...
    > > >
    > > > "Lerp" <> wrote in message
    > > > news:%23dwk$...
    > > > > 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 ...).
    > > >
    > > >
    > > > ---
    > > >
    > > > Checked by AVG anti-virus system (http://www.grisoft.com).
    > > > Version: 6.0.677 / Virus Database: 439 - Release Date: 5/4/2004
    > > >

    > 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
    > > > > curClientID = e.item.FindControl("clientid")...."

    >
    > 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/default.asp?url=/library/en-us/cpref/html/
    frlrfSystemWebUIControlClassClientIDTopic.asp
    >
    > "Lerp" <> wrote in message
    > news:...
    > > 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
    > >
    > >
    > >
    > >
    > >
    > > "jm" <> wrote in message
    > > news:BPanc.6774$z06.1276684@attbi_s01...
    > > >
    > > > "Lerp" <> wrote in message
    > > > news:%23dwk$...
    > > > > 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 ...).
    > > >
    > > >
    > > > ---
    > > >
    > > > Checked by AVG anti-virus system (http://www.grisoft.com).
    > > > Version: 6.0.677 / Virus Database: 439 - Release Date: 5/4/2004
    > > >

    > 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
    > > > > curClientID = e.item.FindControl("clientid")...."

    >
    > 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/default.asp?url=/library/en-us/cpref/html/
    frlrfSystemWebUIControlClassClientIDTopic.asp
    >
    >
     
    Lerp, May 9, 2004
    #5
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Replies:
    0
    Views:
    625
  2. Replies:
    1
    Views:
    888
    Jack Klein
    Apr 13, 2005
  3. truce
    Replies:
    5
    Views:
    662
    truce
    Jan 14, 2006
  4. Iñaki Baz Castillo
    Replies:
    7
    Views:
    893
    Iñaki Baz Castillo
    Jan 12, 2010
  5. David Mark
    Replies:
    17
    Views:
    248
    David Mark
    Mar 23, 2010
Loading...

Share This Page