By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,105 Members | 2,560 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,105 IT Pros & Developers. It's quick & easy.

Dynamically added Checkbox in Gridview

P: n/a
I am dynamically adding a checkbox in a gridview and I find there are several
things that I cannot figure out how to address.

1. The width of the checkbox column is very wide. I've tried adding
properties and Item Style to the column but it has no effect. Is there
someway to size this column to be smaller? I removed the CssClass property
and it had no effect on the size as well.

2. The gridview is sortable using javascript. Is there any way to keep
checkboxes selected after the sort?

<asp:GridView ID="GridViewResults" runat="server"
AutoGenerateColumns="False"
CssClass="sortable" >
<Columns>
<asp:TemplateField HeaderText="Select" >
<ItemTemplate>
<asp:CheckBox ID="chkSelect" runat="server" />
</ItemTemplate>
<ItemStyle width="20px" />
</asp:TemplateField>
<asp:HyperLinkField DataNavigateUrlFields="QuoteID"
DataNavigateUrlFormatString="SetupSummary.aspx?Quo teID={0}"
DataTextField="UserFriendlyQuoteID" HeaderText="Quote ID"
NavigateUrl="~/SetupSummary.aspx"
SortExpression="UserFriendlyQuoteID" />
<asp:BoundField DataField="QuoteStatusDescription"
HeaderText="Status" />
<asp:BoundField DataField="AcceptedDate" HeaderText="Accept
Date" />
<asp:BoundField DataField="Notes" HeaderText="Notes" />
</Columns>
</asp:GridView>

Any thoughts would be appreciated.
Bill
Aug 1 '06 #1
Share this Question
Share on Google+
1 Reply


P: n/a
If the checkbox is wider than 20px then the column will be as wide as
the checkbox control. Try setting CssClass of the column and set these
properties for the class

..CheckBoxColumnClass
{
width: 20px;
overflow: hidden; /* <- that will hide anything that is wider than 20px
inside the cell */
}

Don't really know much about javascript sorting gridviews, so I can't
help you there.

//Mats

Bill44077 wrote:
I am dynamically adding a checkbox in a gridview and I find there are several
things that I cannot figure out how to address.

1. The width of the checkbox column is very wide. I've tried adding
properties and Item Style to the column but it has no effect. Is there
someway to size this column to be smaller? I removed the CssClass property
and it had no effect on the size as well.

2. The gridview is sortable using javascript. Is there any way to keep
checkboxes selected after the sort?

<asp:GridView ID="GridViewResults" runat="server"
AutoGenerateColumns="False"
CssClass="sortable" >
<Columns>
<asp:TemplateField HeaderText="Select" >
<ItemTemplate>
<asp:CheckBox ID="chkSelect" runat="server" />
</ItemTemplate>
<ItemStyle width="20px" />
</asp:TemplateField>
<asp:HyperLinkField DataNavigateUrlFields="QuoteID"
DataNavigateUrlFormatString="SetupSummary.aspx?Quo teID={0}"
DataTextField="UserFriendlyQuoteID" HeaderText="Quote ID"
NavigateUrl="~/SetupSummary.aspx"
SortExpression="UserFriendlyQuoteID" />
<asp:BoundField DataField="QuoteStatusDescription"
HeaderText="Status" />
<asp:BoundField DataField="AcceptedDate" HeaderText="Accept
Date" />
<asp:BoundField DataField="Notes" HeaderText="Notes" />
</Columns>
</asp:GridView>

Any thoughts would be appreciated.
Bill
Aug 1 '06 #2

This discussion thread is closed

Replies have been disabled for this discussion.