all groups > asp.net datagrid control > june 2006 >
You're in the

asp.net datagrid control

group:

Checkbox in template coloumn


Re: Checkbox in template coloumn Ken Cox [Microsoft MVP]
6/24/2006 7:28:28 PM
asp.net datagrid control:
Hi Clear (real names are considered more polite)

You just need to set the checked value to the boolean. Here's the idea, full
code below.

<asp:templatecolumn headertext="Boolean">
<itemtemplate>
<asp:checkbox id="CheckBox1" runat="server"
checked='<%# DataBinder.Eval(Container, "DataItem.Boolean") %>' />
<br />
</itemtemplate>

Let us know if this helps?

Ken
Microsoft MVP [ASP.NET]

<%@ Page Language="VB" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<script runat="server">

Function CreateDataSource() As Data.DataTable
Dim dt As New Data.DataTable
Dim dr As Data.DataRow
dt.Columns.Add(New Data.DataColumn _
("IntegerValue", GetType(Int32)))
dt.Columns.Add(New Data.DataColumn _
("StringValue", GetType(String)))
dt.Columns.Add(New Data.DataColumn _
("CurrencyValue", GetType(Double)))
dt.Columns.Add(New Data.DataColumn _
("Boolean", GetType(Boolean)))
Dim i As Integer
For i = 0 To 5
dr = dt.NewRow()
dr(0) = i
dr(1) = "Item " + i.ToString()
dr(2) = 1.23 * (i + 1)
dr(3) = (i <> 4)
dt.Rows.Add(dr)
Next i
Return dt
End Function

Protected Sub Page_Load(ByVal sender As Object, ByVal e As
System.EventArgs)
If Not IsPostBack Then
dg3.DataSource = CreateDataSource()
dg3.DataBind()
End If
End Sub
</script>

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Check a checkbox</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:datagrid id="dg3" runat="server" autogeneratecolumns="False">
<columns>
<asp:templatecolumn headertext="Boolean">
<itemtemplate>
<asp:checkbox id="CheckBox1" runat="server"
checked='<%# DataBinder.Eval(Container, "DataItem.Boolean") %>' />
<br />
</itemtemplate>
</asp:templatecolumn>
<asp:templatecolumn headertext="StringValue">
<itemtemplate>
<asp:label runat="server"
text='<%# DataBinder.Eval(Container, "DataItem.StringValue") %>'>
</asp:label>
</itemtemplate>
</asp:templatecolumn>
</columns>
</asp:datagrid>
</div>
</form>
</body>
</html>


[quoted text, click to view]

Checkbox in template coloumn ClearConcepts
6/25/2006 1:54:26 AM

Hi,

I am using checkbox in template column of datagrid in aspx page.

I am fetching boolean field from database and binding to this template
column.

If the values is "true" checkbox should checkd. otherwise it should be
unchecked.

How to do this?

Please suggest me

--
Regards
ClearConcepts

AddThis Social Bookmark Button