Datagrid query

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

    #1

    Datagrid query

    Hi,

    I have a datagrid being populated using an sqldatareader. One of the
    columns returns a bit value which currently gets displayed as 'True' or
    'False'.

    I would like to be able to display an image of a tick when this value is
    true, and have placed an asp.net image control within the relevant template
    column. I presume I can achieve this within the databinding event of the
    grid, but am unsure as to quite how!

    I would be grateful if anyone could shed some light on this!

    Many thanks, Carl
    carl.howarth@m-s-solutions.co.uk


  • Jon Sequeira

    #2
    Re: Datagrid query

    In the .aspx file you could set the Image's Visible property to the
    databound value, something like this:

    <asp:Image Visible="<%# CBool(DataBinde r.Eval(Containe r,
    "DataItem.showT ickGraphic") %>"> </asp:Image>

    If this will acheive what you're looking for, it's a little less complex
    than diving into the databinding events.

    Hope that's useful,

    --Jon

    "Carl Howarth" <carl.howarth @m-s-solutions.co.uk > wrote in message
    news:#qipjsuRDH A.2020@TK2MSFTN GP11.phx.gbl...[color=blue]
    > Hi,
    >
    > I have a datagrid being populated using an sqldatareader. One of the
    > columns returns a bit value which currently gets displayed as 'True' or
    > 'False'.
    >
    > I would like to be able to display an image of a tick when this value is
    > true, and have placed an asp.net image control within the relevant[/color]
    template[color=blue]
    > column. I presume I can achieve this within the databinding event of the
    > grid, but am unsure as to quite how!
    >
    > I would be grateful if anyone could shed some light on this!
    >
    > Many thanks, Carl
    > carl.howarth@m-s-solutions.co.uk
    >
    >[/color]


    Comment

    • John G

      #3
      Re: Datagrid query

      Hi Carl,

      From what I can see you are in the right direction but you cannot use
      the FindControl method of the DataGrid itself to find a control in a
      templatecolumn. .. there would be one control with that ID for each row
      in the grid.

      So... instead of

      dgExistingFiles .Controls("imTi ck").Visible = True

      you need to use the DataGridItemEve ntArgs e param that is passed in to
      get
      a reference to the control. For ex: if your image is the only control
      in the first column of the datagrid:

      e.Item.Cells[0].Controls[1].Visible = false

      would do the trick (Controls[1] because the system always adds a
      literal control before your server control, at least this is what I
      have found)

      If its in the second column use Cells[1] instead, etc... If there are
      other controls in the column you will have to play around with the
      Controls[] index to find the right one.

      John


      "Carl Howarth" <carl.howarth @m-s-solutions.co.uk > wrote in message news:<#dI5uf4RD HA.2144@TK2MSFT NGP11.phx.gbl>. ..[color=blue]
      > Thanks Jon,
      >
      > This is the way in which I got around the problem, I would however be v
      > interested to find out how to alter a control's properties from the backend
      > code... could anybody point me in the right direction?
      >
      > Thanks, Carl
      >
      > "Jon Sequeira" <jsequeir@twcny .rr.com> wrote in message
      > news:%23nXNk0wR DHA.212@TK2MSFT NGP10.phx.gbl.. .[color=green]
      > > In the .aspx file you could set the Image's Visible property to the
      > > databound value, something like this:
      > >
      > > <asp:Image Visible="<%# CBool(DataBinde r.Eval(Containe r,
      > > "DataItem.showT ickGraphic") %>"> </asp:Image>
      > >
      > > If this will acheive what you're looking for, it's a little less complex
      > > than diving into the databinding events.
      > >
      > > Hope that's useful,
      > >
      > > --Jon
      > >
      > > "Carl Howarth" <carl.howarth @m-s-solutions.co.uk > wrote in message
      > > news:#qipjsuRDH A.2020@TK2MSFTN GP11.phx.gbl...[color=darkred]
      > > > Hi,
      > > >
      > > > I have a datagrid being populated using an sqldatareader. One of the
      > > > columns returns a bit value which currently gets displayed as 'True' or
      > > > 'False'.
      > > >
      > > > I would like to be able to display an image of a tick when this value is
      > > > true, and have placed an asp.net image control within the relevant[/color][/color]
      > template[color=green][color=darkred]
      > > > column. I presume I can achieve this within the databinding event of[/color][/color]
      > the[color=green][color=darkred]
      > > > grid, but am unsure as to quite how!
      > > >
      > > > I would be grateful if anyone could shed some light on this!
      > > >
      > > > Many thanks, Carl
      > > > carl.howarth@m-s-solutions.co.uk
      > > >
      > > >[/color]
      > >
      > >[/color][/color]

      Comment

      Working...