Getting inside a template column

Discussion in 'ASP .Net Datagrid Control' started by G Dean Blake, Jan 19, 2005.

  1. G Dean Blake

    G Dean Blake Guest

    I'm writing a Grid Print component and I am being passed a datagrid. I have
    to take apart the various columns in order to print them.

    In the case where the grid had a template column that is a text box, I am
    finding that myItem.Cells(i).Controls(0).GetType.Name gets "LiteralControl".

    I can't seem to find out how to tell what kind of control it is i.e.
    dropdownlist, textbox etc. I suppose I could try casting it as a textbox to
    see if it throws an exception but I don't want to do that as it would slow
    things down.

    Anyone know how to see what kind of control it is?
    Thanks,
    G
    G Dean Blake, Jan 19, 2005
    #1
    1. Advertising

  2. G Dean Blake

    Elton Wang Guest

    Suppose in TemplateColumn there are two items as follows:

    <asp:TemplateColumn SortExpression="Send"
    HeaderText="Send">
    <ItemTemplate>
    <asp:Label Width="50px" Text='<%# iif
    (convert.tostring(DataBinder.eval
    (Container.DataItem,"Send"))="True", "Yes","No") %>'
    Runat=server ID="lblSend">
    </asp:Label>
    </ItemTemplate>
    <EditItemTemplate>
    <asp:CheckBox ID="ckSend" Runat=server
    Width="50" Checked='<%# iif(convert.tostring
    (DataBinder.eval(Container.DataItem,"Send"))="True",
    true,false) %>'>
    </asp:CheckBox>
    </EditItemTemplate>
    </asp:TemplateColumn>

    In that case, you will get:
    myItem.Cells(i).Controls(0).GetType.Name (LiteralControl)
    myItem.Cells(i).Controls(1).GetType.Name (CheckBox)

    Hope it's helpful to you.

    Elton Wang


    >-----Original Message-----
    >I'm writing a Grid Print component and I am being passed

    a datagrid. I have
    >to take apart the various columns in order to print them.
    >
    >In the case where the grid had a template column that is

    a text box, I am
    >finding that myItem.Cells(i).Controls(0).GetType.Name

    gets "LiteralControl".
    >
    >I can't seem to find out how to tell what kind of control

    it is i.e.
    >dropdownlist, textbox etc. I suppose I could try casting

    it as a textbox to
    >see if it throws an exception but I don't want to do that

    as it would slow
    >things down.
    >
    >Anyone know how to see what kind of control it is?
    >Thanks,
    >G
    >
    >
    >.
    >
    Elton Wang, Jan 19, 2005
    #2
    1. Advertising

  3. G Dean Blake

    G Dean Blake Guest

    Again, thank you :)
    G
    "Elton Wang" <> wrote in message
    news:0c9801c4fe6b$0d784c80$...
    >
    > Suppose in TemplateColumn there are two items as follows:
    >
    > <asp:TemplateColumn SortExpression="Send"
    > HeaderText="Send">
    > <ItemTemplate>
    > <asp:Label Width="50px" Text='<%# iif
    > (convert.tostring(DataBinder.eval
    > (Container.DataItem,"Send"))="True", "Yes","No") %>'
    > Runat=server ID="lblSend">
    > </asp:Label>
    > </ItemTemplate>
    > <EditItemTemplate>
    > <asp:CheckBox ID="ckSend" Runat=server
    > Width="50" Checked='<%# iif(convert.tostring
    > (DataBinder.eval(Container.DataItem,"Send"))="True",
    > true,false) %>'>
    > </asp:CheckBox>
    > </EditItemTemplate>
    > </asp:TemplateColumn>
    >
    > In that case, you will get:
    > myItem.Cells(i).Controls(0).GetType.Name (LiteralControl)
    > myItem.Cells(i).Controls(1).GetType.Name (CheckBox)
    >
    > Hope it's helpful to you.
    >
    > Elton Wang
    >
    >
    >>-----Original Message-----
    >>I'm writing a Grid Print component and I am being passed

    > a datagrid. I have
    >>to take apart the various columns in order to print them.
    >>
    >>In the case where the grid had a template column that is

    > a text box, I am
    >>finding that myItem.Cells(i).Controls(0).GetType.Name

    > gets "LiteralControl".
    >>
    >>I can't seem to find out how to tell what kind of control

    > it is i.e.
    >>dropdownlist, textbox etc. I suppose I could try casting

    > it as a textbox to
    >>see if it throws an exception but I don't want to do that

    > as it would slow
    >>things down.
    >>
    >>Anyone know how to see what kind of control it is?
    >>Thanks,
    >>G
    >>
    >>
    >>.
    >>
    G Dean Blake, Jan 19, 2005
    #3
    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. Dexter
    Replies:
    1
    Views:
    405
    Eliyahu Goldin
    Jan 18, 2005
  2. G Dean Blake

    Getting inside a template column

    G Dean Blake, Jan 19, 2005, in forum: ASP .Net
    Replies:
    1
    Views:
    292
    Eliyahu Goldin
    Jan 20, 2005
  3. Ken Varn
    Replies:
    1
    Views:
    963
    Ken Varn
    Aug 19, 2005
  4. Charleees
    Replies:
    2
    Views:
    8,185
    Eliyahu Goldin
    Jun 20, 2006
  5. Ravichandran Mahalingam

    Bound Column or Template Column (w dAdapater?) in DataGrid

    Ravichandran Mahalingam, Jan 9, 2004, in forum: ASP .Net Datagrid Control
    Replies:
    0
    Views:
    203
    Ravichandran Mahalingam
    Jan 9, 2004
Loading...

Share This Page