I'm a little confused.
------------------------------------------------------------------------
Why is the asp:CheckBoxField unable to be added as a field to a GridView object?
------------------------------------------------------------------------
In other words, I have a <GridView> that has currently 4 columns.
1). I want to add an <asp:CheckBoxField> those columns.
2). When I click on the <GridView> and click Edit Columns, Available fields at the top of the window says:
(All Fields)
Bound Fields
CheckBoxField.
3). When I click on the CheckBoxField the Add button becomes disabled.
It depends on the schema that the datasource that you are binding to exposes.
In SQL Server if you have a bit field exposed to your SQLDAtaSource schema (based on your select statement) that field will be listed in a tree under the CheckBoxField (tree fashio)- you could add that field. If no bit fields are present (or you are using a
XML datasource that does not expose anything but strings) you will not be able to add the field.
If you want you could always add a template field, edit that template and bind the text property of the checkbox to a string field in your schema.
HTH
JD
This posting is provided "AS IS" with no warranties, and confers no rights.
We Are Hiring
OK, I created a column in my resultset that is cast as a bit (CONVERT(bit,0) as Selected) and the checkboxfield show up just fine, except that it is read only. What I am looking to do is use the GridView as a smart CheckBoxList. Would I have to actually have
a real bit field returned in the results of the stored procedure to make this work?
drdexter33
Contributor
2289 Points
889 Posts
<asp:CheckBoxField /> in an <asp:GridView /> object
Oct 13, 2005 01:38 PM|LINK
I'm a little confused.
------------------------------------------------------------------------
Why is the asp:CheckBoxField unable to be added as a field to a GridView object?
------------------------------------------------------------------------
In other words, I have a <GridView> that has currently 4 columns.
1). I want to add an <asp:CheckBoxField> those columns.
2). When I click on the <GridView> and click Edit Columns, Available fields at the top of the window says:
(All Fields)
Bound Fields
CheckBoxField.
3). When I click on the CheckBoxField the Add button becomes disabled.
------------------------------------------------------------------------
I've tried to add in the code like this:
------------------------------------------------------------------------
<Columns>
<asp:CheckBoxField Text="Checkbox"/>
<asp:BoundField DataField="RoleName" HeaderText="RoleName" SortExpression="RoleName" />
<asp:BoundField DataField="UserId" HeaderText="UserId" SortExpression="UserId" >
<ItemStyle CssClass="dgHiddenColumn" />
<HeaderStyle CssClass="dgHiddenColumn" />
</asp:BoundField>
<asp:BoundField DataField="UserName" HeaderText="UserName" SortExpression="UserName" />
<asp:BoundField DataField="RoleId" HeaderText="RoleId" SortExpression="RoleId" >
<ItemStyle CssClass="dgHiddenColumn" />
<HeaderStyle CssClass="dgHiddenColumn" />
</asp:BoundField>
</Columns>
But that didnt' work either.
Any ideas?
thanks.
doug
jdixon
Contributor
2210 Points
438 Posts
Microsoft
Re: <asp:CheckBoxField /> in an <asp:GridView /> object
Oct 14, 2005 03:59 PM|LINK
In SQL Server if you have a bit field exposed to your SQLDAtaSource schema (based on your select statement) that field will be listed in a tree under the CheckBoxField (tree fashio)- you could add that field. If no bit fields are present (or you are using a XML datasource that does not expose anything but strings) you will not be able to add the field.
If you want you could always add a template field, edit that template and bind the text property of the checkbox to a string field in your schema.
HTH
JD
We Are Hiring
douglas.reil...
All-Star
23315 Points
4647 Posts
Re: <asp:CheckBoxField /> in an <asp:GridView /> object
Nov 10, 2005 02:34 PM|LINK
Programming Microsoft Web Forms
My Blog
curtisdehave...
Member
77 Points
126 Posts
Re: <asp:CheckBoxField /> in an <asp:GridView /> object
Oct 27, 2007 01:21 PM|LINK
Better late than never... I happened across this post searching for the answer to the same question. It takes a little work, but one answer lies here:
http://msdn.microsoft.com/msdnmag/issues/06/05/CuttingEdge/default.aspx