Datagrid - include jpegs

Discussion in 'ASP .Net' started by Jonathan, Feb 18, 2008.

  1. Jonathan

    Jonathan Guest

    In one of the 4 output columns of my Datagrid, I have a Yes/No Boolean
    field.

    I'd like to show a graphical tick (e.g. tick.jpg) or a cross e.g.
    (cross.jpg) instead of True/False or Yes/No.

    How could I do that? Here's the code:


    </head>

    <%@ Page language="VB" Debug="true" %>
    <%@ Import Namespace="System.Data" %>
    <%@ Import Namespace="System.Data.OleDb" %>

    <script language="VB" runat="server">

    Sub Page_Load(Sender as Object, E as EventArgs)

    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\mysite\myaccessdb.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, "qryDataGrid01")

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

    End Sub
    </script>


    <asp:DataGrid runat="server" id="oGrid" BackColor="#eeeeee"
    HorizontalAlign="Left">
    <HeaderStyle Font-Bold="True"/>
    <AlternatingItemStyle BackColor="White" />
    </asp:datagrid>
    Jonathan, Feb 18, 2008
    #1
    1. Advertising

  2. "Jonathan" <> wrote in message news:fpbmta$vak$...

    > In one of the 4 output columns of my Datagrid,


    DataGrid? Are you still using Visual Studio.NET 2003...?

    > I'd like to show a graphical tick (e.g. tick.jpg) or a cross e.g.
    > (cross.jpg) instead of True/False or Yes/No.


    http://authors.aspalliance.com/aspxtreme/webforms/controls/addingtemplatecolumnstodatagrid.aspx

    > sConn += "Data Source=D:\inetpub\www\mysite\myaccessdb.mdb;"


    Surely not...? The above implies that your database is in your website's
    virtual root, meaning that it is fully accessible through a browser:

    http://www.mysite.com/myaccessdb.mdb


    --
    Mark Rae
    ASP.NET MVP
    http://www.markrae.net
    Mark Rae [MVP], Feb 18, 2008
    #2
    1. Advertising

  3. Jonathan

    Masudur Guest

    On Feb 18, 4:31 pm, "Jonathan" <> wrote:
    > In one of the 4 output columns of my Datagrid, I have a Yes/No Boolean
    > field.
    >
    > I'd like to show a graphical tick (e.g. tick.jpg) or a cross e.g.
    > (cross.jpg) instead of True/False or Yes/No.
    >
    > How could I do that? Here's the code:
    >
    > </head>
    >
    > <%@ Page language="VB" Debug="true" %>
    > <%@ Import Namespace="System.Data" %>
    > <%@ Import Namespace="System.Data.OleDb" %>
    >
    > <script language="VB" runat="server">
    >
    > Sub Page_Load(Sender as Object, E as EventArgs)
    >
    > 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\mysite\myaccessdb.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, "qryDataGrid01")
    >
    > 'Set the grid source to the dataset and bind the data
    > oGrid.DataSource=oDataSet.Tables("qryDataGrid01").DefaultView
    > oGrid.DataBind()
    >
    > End Sub
    > </script>
    >
    > <asp:DataGrid runat="server" id="oGrid" BackColor="#eeeeee"
    > HorizontalAlign="Left">
    > <HeaderStyle Font-Bold="True"/>
    > <AlternatingItemStyle BackColor="White" />
    > </asp:datagrid>


    Hi...

    You can change your column's item template and add a image in item
    template...
    next in item data bound depenting on your data value change source of
    the image...

    please take a look at this section...
    http://www.asp.net/learn/data-access/#formatting

    Thanks
    Md. Masudur Rahman
    www.munna.shatkotha.com
    www.kaz.com.bd
    Masudur, Feb 18, 2008
    #3
  4. Jonathan

    gnewsgroup Guest

    On Feb 18, 5:31 am, "Jonathan" <> wrote:
    > In one of the 4 output columns of my Datagrid, I have a Yes/No Boolean
    > field.
    >
    > I'd like to show a graphical tick (e.g. tick.jpg) or a cross e.g.
    > (cross.jpg) instead of True/False or Yes/No.
    >
    > How could I do that? Here's the code:
    >
    > </head>
    >
    > <%@ Page language="VB" Debug="true" %>
    > <%@ Import Namespace="System.Data" %>
    > <%@ Import Namespace="System.Data.OleDb" %>
    >
    > <script language="VB" runat="server">
    >
    > Sub Page_Load(Sender as Object, E as EventArgs)
    >
    > 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\mysite\myaccessdb.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, "qryDataGrid01")
    >
    > 'Set the grid source to the dataset and bind the data
    > oGrid.DataSource=oDataSet.Tables("qryDataGrid01").DefaultView
    > oGrid.DataBind()
    >
    > End Sub
    > </script>
    >
    > <asp:DataGrid runat="server" id="oGrid" BackColor="#eeeeee"
    > HorizontalAlign="Left">
    > <HeaderStyle Font-Bold="True"/>
    > <AlternatingItemStyle BackColor="White" />
    > </asp:datagrid>


    If you *can* use ASP.NET 2.0, you can use the ImageField property of
    GridView. An example is available here:

    http://authors.aspalliance.com/aspx...webcontrols/demos/GridViewImageField.aspx.src

    Also, as Mark has pointed out, your database is located in your web
    folder and can be directly downloaded, which needs to be fixed.
    gnewsgroup, Feb 18, 2008
    #4
    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. Brian Henry

    created jpegs

    Brian Henry, Jul 21, 2003, in forum: ASP .Net
    Replies:
    2
    Views:
    388
    Brian Henry
    Jul 21, 2003
  2. Aaron Davies
    Replies:
    4
    Views:
    629
    dar7yl
    Jun 30, 2004
  3. Jim Higson
    Replies:
    1
    Views:
    499
    Jim Higson
    Sep 21, 2004
  4. Replies:
    1
    Views:
    334
    John Timney \( MVP \)
    May 4, 2006
  5. Andreas Bogenberger
    Replies:
    3
    Views:
    881
    Andreas Bogenberger
    Feb 22, 2008
Loading...

Share This Page