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

B

Burak

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
 
S

Scott Mitchell [MVP]

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:
http://datawebcontrols.com/faqs/ProgrammaticAccess/AccessingTemplateColumnContents.shtml

Happy Programming!

--

Scott Mitchell
(e-mail address removed)
http://www.4GuysFromRolla.com
http://www.ASPFAQs.com
http://www.ASPMessageboard.com

* When you think ASP, think 4GuysFromRolla.com!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Staff online

Members online

Forum statistics

Threads
473,755
Messages
2,569,534
Members
45,008
Latest member
Rahul737

Latest Threads

Top