Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > ASP .Net Datagrid Control > Checkbox in template coloumn

Reply
Thread Tools

Checkbox in template coloumn

 
 
ClearConcepts
Guest
Posts: n/a
 
      06-24-2006

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


 
Reply With Quote
 
 
 
 
Ken Cox [Microsoft MVP]
Guest
Posts: n/a
 
      06-24-2006
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>


"ClearConcepts" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
>
> 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
>
>



 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
how to transfer time from datetime coloumn to another coloumn YMPN ASP .Net 2 01-25-2007 05:22 PM
who can we get the data from XLS Sheet and print the selected coloumn in jsp page Garg Java 1 05-11-2006 04:56 PM
How can i get each coloumn of a 2D array as 1D arrays?? Renjini C++ 2 01-28-2006 10:16 PM
Re: A Newbie Question about template template template tom_usenet C++ 0 07-24-2003 12:06 PM
Re: A Newbie Question about template template template Chris Theis C++ 2 07-24-2003 09:42 AM



Advertisments