Datagrid - include jpegs

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Jonathan

    Datagrid - include jpegs

    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="Syst em.Data" %>
    <%@ Import Namespace="Syst em.Data.OleDb" %>

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

    Sub Page_Load(Sende r as Object, E as EventArgs)

    Dim oConn As OleDbConnection
    Dim oComm As OleDbDataAdapte r
    Dim sConn As String
    Dim sComm As String
    Dim oDataSet As New DataSet

    'Build the connection string
    sConn = "Provider=Micro soft.Jet.OLEDB. 4.0;"
    sConn += "Data Source=D:\inetp ub\www\mysite\m yaccessdb.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 OleDbDataAdapte r(sComm, oConn)

    'Fill the dataset with the results of the query
    oComm.Fill(oDat aSet, "qryDataGrid01" )

    'Set the grid source to the dataset and bind the data
    oGrid.DataSourc e=oDataSet.Tabl es("qryDataGrid 01").DefaultVie w
    oGrid.DataBind( )

    End Sub
    </script>


    <asp:DataGrid runat="server" id="oGrid" BackColor="#eee eee"
    HorizontalAlign ="Left">
    <HeaderStyle Font-Bold="True"/>
    <AlternatingIte mStyle BackColor="Whit e" />
    </asp:datagrid>





  • Mark Rae [MVP]

    #2
    Re: Datagrid - include jpegs

    "Jonathan" <none@none.comw rote in message news:fpbmta$vak $1@aioe.org...
    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.

    sConn += "Data Source=D:\inetp ub\www\mysite\m yaccessdb.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:




    --
    Mark Rae
    ASP.NET MVP


    Comment

    • Masudur

      #3
      Re: Datagrid - include jpegs

      On Feb 18, 4:31 pm, "Jonathan" <n...@none.comw rote:
      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="Syst em.Data" %>
      <%@ Import Namespace="Syst em.Data.OleDb" %>
      >
      <script language="VB" runat="server">
      >
      Sub Page_Load(Sende r as Object, E as EventArgs)
      >
      Dim oConn As OleDbConnection
      Dim oComm As OleDbDataAdapte r
      Dim sConn As String
      Dim sComm As String
      Dim oDataSet As New DataSet
      >
      'Build the connection string
      sConn = "Provider=Micro soft.Jet.OLEDB. 4.0;"
      sConn += "Data Source=D:\inetp ub\www\mysite\m yaccessdb.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 OleDbDataAdapte r(sComm, oConn)
      >
      'Fill the dataset with the results of the query
      oComm.Fill(oDat aSet, "qryDataGrid01" )
      >
      'Set the grid source to the dataset and bind the data
      oGrid.DataSourc e=oDataSet.Tabl es("qryDataGrid 01").DefaultVie w
      oGrid.DataBind( )
      >
      End Sub
      </script>
      >
      <asp:DataGrid runat="server" id="oGrid" BackColor="#eee eee"
      HorizontalAlign ="Left">
      <HeaderStyle Font-Bold="True"/>
      <AlternatingIte mStyle BackColor="Whit e" />
      </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...
      Build web apps and services that run on Windows, Linux, and macOS using C#, HTML, CSS, and JavaScript. Get started for free on Windows, Linux, or macOS.


      Thanks
      Md. Masudur Rahman


      Comment

      • gnewsgroup

        #4
        Re: Datagrid - include jpegs

        On Feb 18, 5:31 am, "Jonathan" <n...@none.comw rote:
        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="Syst em.Data" %>
        <%@ Import Namespace="Syst em.Data.OleDb" %>
        >
        <script language="VB" runat="server">
        >
        Sub Page_Load(Sende r as Object, E as EventArgs)
        >
        Dim oConn As OleDbConnection
        Dim oComm As OleDbDataAdapte r
        Dim sConn As String
        Dim sComm As String
        Dim oDataSet As New DataSet
        >
        'Build the connection string
        sConn = "Provider=Micro soft.Jet.OLEDB. 4.0;"
        sConn += "Data Source=D:\inetp ub\www\mysite\m yaccessdb.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 OleDbDataAdapte r(sComm, oConn)
        >
        'Fill the dataset with the results of the query
        oComm.Fill(oDat aSet, "qryDataGrid01" )
        >
        'Set the grid source to the dataset and bind the data
        oGrid.DataSourc e=oDataSet.Tabl es("qryDataGrid 01").DefaultVie w
        oGrid.DataBind( )
        >
        End Sub
        </script>
        >
        <asp:DataGrid runat="server" id="oGrid" BackColor="#eee eee"
        HorizontalAlign ="Left">
        <HeaderStyle Font-Bold="True"/>
        <AlternatingIte mStyle BackColor="Whit e" />
        </asp:datagrid>
        If you *can* use ASP.NET 2.0, you can use the ImageField property of
        GridView. An example is available here:



        Also, as Mark has pointed out, your database is located in your web
        folder and can be directly downloaded, which needs to be fixed.

        Comment

        Working...