yes!
here's how to add checkbox items to a datagrid in asp.net using c#
e.g. datagrid html code:
.....(html and other bits)
<asp:datagrid id="DgUserPermi ssions" style="Z-INDEX: 101; LEFT: 44px;
POSITION: absolute; TOP: 152px" runat="server" AutoGenerateCol umns="False"
Height="75px" Width="598px" DataKeyField="P roject_User_ID" >
<AlternatingIte mStyle BackColor="Ligh tGray"></AlternatingItem Style>
<HeaderStyle BackColor="Gray "></HeaderStyle>
<Columns>
<asp:EditComman dColumn ButtonType="Pus hButton" UpdateText="Upd ate"
CancelText="Can cel" EditText="Edit" ></asp:EditCommand Column>
.....(some other columns)
<asp:TemplateCo lumn HeaderText="Dis abled">
<ItemStyle HorizontalAlign ="Center"></ItemStyle>
<ItemTemplate >
<asp:CheckBox id="Disabled" runat="server" Checked='<%#
DataBinder.Eval (Container.Data Item, "<NAME OF DATASET COL GOES HERE!!>")
%>'>
</asp:CheckBox>
</ItemTemplate>
</asp:TemplateCol umn>
......(some more columns and html)
which is bound to a dataset (in my case dynamically not at design time)
during the pageload -> if (!page.ispostba ck) etc.
the dataset column is a bit column in this case
the databinder.eval appears (from what i can tell) to convert the 'bit'
value to something that the asp:checkbox can cope with
if you know what datatype is returned you can put a load of stuff in with
formatting and so on
(note the special syntax "<%#=" this is only executed when the 'databind'
method is called)
and to get the values out?
assuming that you are using the update/edit/cancel button stuff provided, in
your 'update' event
something like this:
(on the codebehind page)
private void DgUserPermissio ns_Update(objec t source,
System.Web.UI.W ebControls.Data GridCommandEven tArgs e)
put
CheckBox cb = (CheckBox)e.Ite m.Cells[2].FindControl("D isabled");
Boolean Disabled = cb.Checked;
2 means second column in the grid in this case, the "(checkbox)e... ." syntax
is casting the control into a checkbox (which it is, seems silly to me)
you can then access the value
/*
i have had problems where by the edit/cancel buttons were being added but
the hander was missing
(found inside the unexpanded) "Web Form Designer generated code" section
so you have to add in something like (again on the code behind page)
this.DgUserPerm issions.CancelC ommand += new
System.Web.UI.W ebControls.Data GridCommandEven tHandler(this.D gUserPermission s
_Cancel);
this.DgUserPerm issions.EditCom mand += new
System.Web.UI.W ebControls.Data GridCommandEven tHandler(this.D gUserPermission s
_Edit);
this.DgUserPerm issions.UpdateC ommand += new
System.Web.UI.W ebControls.Data GridCommandEven tHandler(this.D gUserPermission s
_Update);
you can put whatever you like in with template columns drop downs, special
formatting and so on
if you don't like c# then make the effort to learn it
i was a vb6 programmer of 5 years and have made the switch (eventually!)
[there are some in depth articles about the datagrid on the 4guysfromrolla
website]
"Sebi" <an*******@disc ussions.microso ft.com> wrote in message
news:0a******** *************** *****@phx.gbl.. .
Hello all
is it possible to add a checkbox in a DataGrid for
Boolean Data?
Thanks in advance