How to prevent a checkbox from showing up in a datagrid with no records?

Ask a Question related to ASP.NET Data Grid Control, Design and Development.

  1. #1

    Default How to prevent a checkbox from showing up in a datagrid with no records?

    Hello,

    I have a datagrid made up of two columns, the first has a checkbox in
    it and the other holds a job id.

    <Columns>
    <asp:TemplateColumn HeaderText="Select"
    HeaderStyle-HorizontalAlign="Center"
    ItemStyle-HorizontalAlign="Center">
    <ItemTemplate>
    <asp:CheckBox ID="chkIncomplete" Runat="server"> </asp:CheckBox>
    </ItemTemplate>
    </asp:TemplateColumn>
    <asp:BoundColumn HeaderText="VJC Ref#" SortExpression="JOB_ID"
    DataField="JOB_ID" HeaderStyle-HorizontalAlign="Center"
    ItemStyle-HorizontalAlign="Center"></asp:BoundColumn>
    </columns>

    When there are no job ids, I insert a blank row into the grid from
    the code behind

    row(1) = "No active job orders have been saved"
    ds.Tables(0).Rows.InsertAt(row, 0)
    dtgActive.DataSource = ds.Tables(0)
    dtgActive.DataBind()

    when I do this however, the checkbox also shows up.

    How can I prevent the checkbox from showing up?

    Thank you,

    Burak
    Burak Guest

  2. Similar Questions and Discussions

    1. How can I prevent SmartTag from showing?
      Hi, I've a webcontrol which inherited from BaseValidator. Under the .Net 2.0, such control has a default function----SmartTag, which is new in...
    2. Howto bind CheckBox to the datagrid/ Then update the database field when the checkbox is clicked.
      I am trying to update the database field when the checkbox is clicked. I am trying to modified the following solution but.. got stuck on the...
    3. How to prevent past dates from showing
      I had the same question and have tried the above. The test works fine, but it shows all the dates incl. the past. How do I define the current date...
    4. datagrid with no records - showing a line
      Hi everyone, Using asp.net and a datagrid - When there are no records returned from the query - is there a way to add/insert a line into the...
    5. I want to prevent accidental updates to records
      I am running Access 2000. I would like to put a simple check box on a form so that if the box is checked that record cannot be edited. If you...
  3. #2

    Default Re: How to prevent a checkbox from showing up in a datagrid withno records?

    > When there are no job ids, I insert a blank row into the grid from
    > the code behind
    >
    > row(1) = "No active job orders have been saved"
    > ds.Tables(0).Rows.InsertAt(row, 0)
    > dtgActive.DataSource = ds.Tables(0)
    > dtgActive.DataBind()
    >
    > when I do this however, the checkbox also shows up.
    >
    > How can I prevent the checkbox from showing up?
    There are a couple options. One would be to set the checkbox column's
    Visible property to False. That is, *before* you call DataBind, do:

    dtgActive.Columns(0).Visible = False

    When the DataGrid is rendered, it will only have one column. If you
    still want the checkbox's column there, but without the checkbox, you'll
    need to programmatically reference the checkbox in the TEmplateColumn
    and set its Visible property to false. More information on
    programmatically referencing Web controls in a TemplateColumn can be
    found here:
    [url]http://datawebcontrols.com/faqs/ProgrammaticAccess/AccessingTemplateColumnContents.shtml[/url]

    Happy Programming!

    --

    Scott Mitchell
    [email]mitchell@4guysfromrolla.com[/email]
    [url]http://www.4GuysFromRolla.com[/url]
    [url]http://www.ASPFAQs.com[/url]
    [url]http://www.ASPMessageboard.com[/url]

    * When you think ASP, think 4GuysFromRolla.com!
    Scott Mitchell [MVP] Guest

Posting Permissions

  • You may not post new threads
  • You may post replies
  • You may not post attachments
  • You may not edit your posts

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139