Bold Text In Datgrid Row If strResult="Purchased"

Discussion in 'ASP .Net' started by Jonathan, Mar 16, 2008.

  1. Jonathan

    Jonathan Guest

    What code would I need to add below to make the text in datagrid rows bold
    when the value of one of the fields, "strResult" equals "Purchased"?

    Function bolPopulateDataGrid() as Boolean

    Dim oConn As OleDbConnection
    Dim oComm As OleDbDataAdapter
    Dim sConn As String
    Dim sComm As String
    Dim oDataSet As New DataSet

    'Build the connection string
    sConn = "Provider=Microsoft.Jet.OLEDB.4.0;"
    sConn += "Data Source=D:\inetpub\www\myweb\fpdb\db.mdb;"
    sConn += "Persist Security Info=False"

    'Build the SQL string
    sComm = "SELECT qryDataGrid01.* "
    sComm += "FROM qryDataGrid01;"


    'Create the connection and command objects
    oConn = New OleDbConnection(sConn)
    oComm = New OleDbDataAdapter(sComm, oConn)

    'Fill the dataset with the results of the query
    oComm.Fill(oDataSet, sComm )

    'Set the grid source to the dataset and bind the data
    oGrid.DataSource=oDataSet.Tables(sComm).DefaultView
    oGrid.DataBind()

    End Function
    Jonathan, Mar 16, 2008
    #1
    1. Advertising

  2. Jonathan

    Jonathan Guest

    Thanks but I wanted specific help relating to the VB.net code I listed.

    I have been trying to decipher the C# code you enter but haven't yet been
    able to get it to work.

    Not to also be ungrateful but deciphering the English grammar you wrote I
    also find cryptic.


    ""Steven Cheng"" <> wrote in message
    news:bxsFRw$...
    > Hi Jonathan,
    >
    > For DataGrid Row customization, a common approach is using the
    > "ItemDataBound" or "ItemCreated" event( GridView has "RowDataBound" and
    > "RowCreated" event). You can get the reference to database column
    > fields(pass through databinding) and change the certain property on Row

    (or
    > individual cells) in it. Here is a simple example that change the row's
    > Font-bold based on a column value:
    >
    > ======================
    > protected void DataGrid1_ItemDataBound(object sender,

    DataGridItemEventArgs
    > e)
    > {
    > if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType ==
    > ListItemType.AlternatingItem)
    > {
    >
    > DataRowView drv = (DataRowView)e.Item.DataItem;
    >
    > long id = (long)drv[0];
    >
    > if (id > 3) e.Item.Font.Bold = true;
    > }
    > }
    > =======================
    >
    > Hope this helps.
    >
    > Sincerely,
    >
    > Steven Cheng
    >
    > Microsoft MSDN Online Support Lead
    >
    >
    > Delighting our customers is our #1 priority. We welcome your comments and
    > suggestions about how we can improve the support we provide to you. Please
    > feel free to let my manager know what you think of the level of service
    > provided. You can send feedback directly to my manager at:
    > .
    >
    > ==================================================
    > This posting is provided "AS IS" with no warranties, and confers no

    rights.
    >
    >
    >
    > --------------------
    > >From: "Jonathan" <>
    > >Subject: Bold Text In Datgrid Row If strResult="Purchased"
    > >Date: Mon, 17 Mar 2008 04:48:22 +1200

    >
    > >
    > >What code would I need to add below to make the text in datagrid rows

    bold
    > >when the value of one of the fields, "strResult" equals "Purchased"?
    > >
    > >Function bolPopulateDataGrid() as Boolean
    > >
    > > Dim oConn As OleDbConnection
    > > Dim oComm As OleDbDataAdapter
    > > Dim sConn As String
    > > Dim sComm As String
    > > Dim oDataSet As New DataSet
    > >
    > > 'Build the connection string
    > > sConn = "Provider=Microsoft.Jet.OLEDB.4.0;"
    > > sConn += "Data Source=D:\inetpub\www\myweb\fpdb\db.mdb;"
    > > sConn += "Persist Security Info=False"
    > >
    > > 'Build the SQL string
    > > sComm = "SELECT qryDataGrid01.* "
    > > sComm += "FROM qryDataGrid01;"
    > >
    > >
    > > 'Create the connection and command objects
    > > oConn = New OleDbConnection(sConn)
    > > oComm = New OleDbDataAdapter(sComm, oConn)
    > >
    > > 'Fill the dataset with the results of the query
    > > oComm.Fill(oDataSet, sComm )
    > >
    > > 'Set the grid source to the dataset and bind the data
    > > oGrid.DataSource=oDataSet.Tables(sComm).DefaultView
    > > oGrid.DataBind()
    > >
    > >End Function
    > >
    > >
    > >
    > >

    >
    Jonathan, Mar 16, 2008
    #2
    1. Advertising

  3. Jonathan

    Jonathan Guest

    My ISP is using .Net 1.1.

    I rarely have been programming in asp.net anyway so it hasn't been an issue.

    I can't add an event with a click because I am using Frontpage. I haven't
    had time to download VS Lite yet.

    Do you know what the event code for ItemDataBound would be? I'd have to type
    it in directly.



    "Mark Rae [MVP]" <> wrote in message
    news:...
    > "Jonathan" <> wrote in message
    > news:u$...
    >
    > > Thanks but I wanted specific help relating to the VB.net code I listed.
    > >
    > > I have been trying to decipher the C# code you enter but haven't yet

    been
    > > able to get it to work.

    >
    > 1) On your DataGrid, add a new ItemDataBound event
    >
    > 2) Drop in the code below:
    >
    > If e.Item.ItemType = ListItemType.Item Or e.Item.ItemType =
    > ListItemType.AlternatingItem Then
    > If e.Item.Cells(0).Text = "Purchased" Then ' amend cell number as
    > necessary
    > e.Item.Font.Bold = True
    > End If
    > End If
    >
    > N.B. I'm not 100% certain about the above code as I never go anywhere near
    > VB.NET, but it should be close enough to get you started...
    >
    > Also, is there any reason that you're using a DataGrid rather than a
    > GridView? Are you still using ASP.NET v1.1...?
    >
    >
    > --
    > Mark Rae
    > ASP.NET MVP
    > http://www.markrae.net
    >
    Jonathan, Mar 16, 2008
    #3
  4. Jonathan

    Steven Cheng Guest

    Hi Jonathan,

    For DataGrid Row customization, a common approach is using the
    "ItemDataBound" or "ItemCreated" event( GridView has "RowDataBound" and
    "RowCreated" event). You can get the reference to database column
    fields(pass through databinding) and change the certain property on Row (or
    individual cells) in it. Here is a simple example that change the row's
    Font-bold based on a column value:

    ======================
    protected void DataGrid1_ItemDataBound(object sender, DataGridItemEventArgs
    e)
    {
    if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType ==
    ListItemType.AlternatingItem)
    {

    DataRowView drv = (DataRowView)e.Item.DataItem;

    long id = (long)drv[0];

    if (id > 3) e.Item.Font.Bold = true;
    }
    }
    =======================

    Hope this helps.

    Sincerely,

    Steven Cheng

    Microsoft MSDN Online Support Lead


    Delighting our customers is our #1 priority. We welcome your comments and
    suggestions about how we can improve the support we provide to you. Please
    feel free to let my manager know what you think of the level of service
    provided. You can send feedback directly to my manager at:
    .

    ==================================================
    This posting is provided "AS IS" with no warranties, and confers no rights.



    --------------------
    >From: "Jonathan" <>
    >Subject: Bold Text In Datgrid Row If strResult="Purchased"
    >Date: Mon, 17 Mar 2008 04:48:22 +1200


    >
    >What code would I need to add below to make the text in datagrid rows bold
    >when the value of one of the fields, "strResult" equals "Purchased"?
    >
    >Function bolPopulateDataGrid() as Boolean
    >
    > Dim oConn As OleDbConnection
    > Dim oComm As OleDbDataAdapter
    > Dim sConn As String
    > Dim sComm As String
    > Dim oDataSet As New DataSet
    >
    > 'Build the connection string
    > sConn = "Provider=Microsoft.Jet.OLEDB.4.0;"
    > sConn += "Data Source=D:\inetpub\www\myweb\fpdb\db.mdb;"
    > sConn += "Persist Security Info=False"
    >
    > 'Build the SQL string
    > sComm = "SELECT qryDataGrid01.* "
    > sComm += "FROM qryDataGrid01;"
    >
    >
    > 'Create the connection and command objects
    > oConn = New OleDbConnection(sConn)
    > oComm = New OleDbDataAdapter(sComm, oConn)
    >
    > 'Fill the dataset with the results of the query
    > oComm.Fill(oDataSet, sComm )
    >
    > 'Set the grid source to the dataset and bind the data
    > oGrid.DataSource=oDataSet.Tables(sComm).DefaultView
    > oGrid.DataBind()
    >
    >End Function
    >
    >
    >
    >
    Steven Cheng, Mar 17, 2008
    #4
  5. "Jonathan" <> wrote in message
    news:u$...

    > Thanks but I wanted specific help relating to the VB.net code I listed.
    >
    > I have been trying to decipher the C# code you enter but haven't yet been
    > able to get it to work.


    1) On your DataGrid, add a new ItemDataBound event

    2) Drop in the code below:

    If e.Item.ItemType = ListItemType.Item Or e.Item.ItemType =
    ListItemType.AlternatingItem Then
    If e.Item.Cells(0).Text = "Purchased" Then ' amend cell number as
    necessary
    e.Item.Font.Bold = True
    End If
    End If

    N.B. I'm not 100% certain about the above code as I never go anywhere near
    VB.NET, but it should be close enough to get you started...

    Also, is there any reason that you're using a DataGrid rather than a
    GridView? Are you still using ASP.NET v1.1...?


    --
    Mark Rae
    ASP.NET MVP
    http://www.markrae.net
    Mark Rae [MVP], Mar 17, 2008
    #5
  6. "Jonathan" <> wrote in message
    news:%...

    [top-posting corrected]

    >> Also, is there any reason that you're using a DataGrid rather than a
    >> GridView? Are you still using ASP.NET v1.1...?

    >
    > My ISP is using .Net 1.1.


    Wow! Sounds like it's time to find a proper ISP...

    > I can't add an event with a click because I am using Frontpage.


    Hmm - you could have mentioned that in your original post, this being an
    ASP.NET newsgroup...

    > Do you know what the event code for ItemDataBound would be? I'd have to
    > type
    > it in directly.


    No idea - what did they tell you in the FrontPage newsgroup...?


    --
    Mark Rae
    ASP.NET MVP
    http://www.markrae.net
    Mark Rae [MVP], Mar 17, 2008
    #6
  7. Hi!

    1. Go to http://msdn.microsoft.com

    2. Enter "DataGrid.ItemDataBound" into the search field in the upper
    left-hand corner.

    3. Choose the first result.

    4. Select the version for ".NET Framework 1.1"

    5. Click on "DataGridItemEventHandler".

    6. Copy the VB code at the top, replacing "Public Delegate" with
    "Protected" and adding "Handles myDataGrid.ItemDataBound" at the
    end.

    Greetings,
    Heinzi
    (teaching people to fish)

    "Jonathan" <> writes:
    > My ISP is using .Net 1.1.
    >
    > I rarely have been programming in asp.net anyway so it hasn't been an issue.
    >
    > I can't add an event with a click because I am using Frontpage. I haven't
    > had time to download VS Lite yet.
    >
    > Do you know what the event code for ItemDataBound would be? I'd have to type
    > it in directly.
    >
    >
    >
    > "Mark Rae [MVP]" <> wrote in message
    > news:...
    >> "Jonathan" <> wrote in message
    >> news:u$...
    >>
    >> > Thanks but I wanted specific help relating to the VB.net code I listed.
    >> >
    >> > I have been trying to decipher the C# code you enter but haven't yet

    > been
    >> > able to get it to work.

    >>
    >> 1) On your DataGrid, add a new ItemDataBound event
    >>
    >> 2) Drop in the code below:
    >>
    >> If e.Item.ItemType = ListItemType.Item Or e.Item.ItemType =
    >> ListItemType.AlternatingItem Then
    >> If e.Item.Cells(0).Text = "Purchased" Then ' amend cell number as
    >> necessary
    >> e.Item.Font.Bold = True
    >> End If
    >> End If
    >>
    >> N.B. I'm not 100% certain about the above code as I never go anywhere near
    >> VB.NET, but it should be close enough to get you started...
    >>
    >> Also, is there any reason that you're using a DataGrid rather than a
    >> GridView? Are you still using ASP.NET v1.1...?
    >>
    >>
    >> --
    >> Mark Rae
    >> ASP.NET MVP
    >> http://www.markrae.net
    >>
    Heinrich Moser, Mar 17, 2008
    #7
  8. Jonathan

    Steven Cheng Guest

    Hi Jonathan,

    Here is the converted VB.NET version of the "ItemDataBound" event handler:

    =================
    Protected Sub DataGrid1_ItemDataBound(ByVal sender As Object, ByVal e As
    System.Web.UI.WebControls.DataGridItemEventArgs) Handles
    DataGrid1.ItemDataBound

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

    Dim id As Long
    Dim drv As DataRowView = e.Item.DataItem

    id = drv(0)

    If id > 3 Then
    e.Item.Font.Bold = True

    End If


    End If
    End Sub
    =================

    as others suggested, ASP.NET 2.0 would be much more powerful and simplified
    for web application development(especially for some basic data access
    tasks).

    Steven Cheng
    Microsoft MSDN Online Support Lead

    Delighting our customers is our #1 priority. We welcome your comments and
    suggestions about how we can improve the support we provide to you. Please
    feel free to let my manager know what you think of the level of service
    provided. You can send feedback directly to my manager at:
    .

    This posting is provided "AS IS" with no warranties, and confers no rights.

    --------------------
    >From: "Jonathan" <>
    >Subject: Re: Bold Text In Datgrid Row If strResult="Purchased"
    >Date: Mon, 17 Mar 2008 11:43:27 +1200


    >
    >My ISP is using .Net 1.1.
    >
    >I rarely have been programming in asp.net anyway so it hasn't been an

    issue.
    >
    >I can't add an event with a click because I am using Frontpage. I haven't
    >had time to download VS Lite yet.
    >
    >Do you know what the event code for ItemDataBound would be? I'd have to

    type
    >it in directly.
    >
    >
    >
    >"Mark Rae [MVP]" <> wrote in message
    >news:...
    >> "Jonathan" <> wrote in message
    >> news:u$...
    >>
    >> > Thanks but I wanted specific help relating to the VB.net code I listed.
    >> >
    >> > I have been trying to decipher the C# code you enter but haven't yet

    >been
    >> > able to get it to work.

    >>
    >> 1) On your DataGrid, add a new ItemDataBound event
    >>
    >> 2) Drop in the code below:
    >>
    >> If e.Item.ItemType = ListItemType.Item Or e.Item.ItemType =
    >> ListItemType.AlternatingItem Then
    >> If e.Item.Cells(0).Text = "Purchased" Then ' amend cell number as
    >> necessary
    >> e.Item.Font.Bold = True
    >> End If
    >> End If
    >>
    >> N.B. I'm not 100% certain about the above code as I never go anywhere

    near
    >> VB.NET, but it should be close enough to get you started...
    >>
    >> Also, is there any reason that you're using a DataGrid rather than a
    >> GridView? Are you still using ASP.NET v1.1...?
    >>
    >>
    >> --
    >> Mark Rae
    >> ASP.NET MVP
    >> http://www.markrae.net
    >>

    >
    >
    >
    Steven Cheng, Mar 18, 2008
    #8
    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. marked
    Replies:
    7
    Views:
    570
    Daniel R. Tobias
    Sep 10, 2003
  2. Guilherme Polo

    Re: Tkinter Bold Text

    Guilherme Polo, Sep 18, 2008, in forum: Python
    Replies:
    0
    Views:
    392
    Guilherme Polo
    Sep 18, 2008
  3. Tony
    Replies:
    0
    Views:
    278
  4. D
    Replies:
    0
    Views:
    203
  5. deostroll
    Replies:
    1
    Views:
    152
    deostroll
    Jan 11, 2008
Loading...

Share This Page