Conditional DataGrid Item and using checkboxes


Contributed by
Rating: 4 stars4 stars4 stars4 stars4 stars / 110
January 01, 2003
Rate this Article:
MEH MEH++


SEARCH ASP FREE
TOOLS YOU CAN USE

advertisement

Conditional DataGrid Item and using checkboxes

Using datagrid in ASP.NET and having one bound column with checkboxes. This code check certain certain conditions before displaying the grid.

Here is the code:


<%@ Page EnableSessionState="false" EnableViewState="false" Language="vb" %>
<%@ import Namespace="System.Data" %>
<%@ import Namespace="System.Data.SqlClient" %>

<script runat="server">
Dim conn as SQLConnection =
   
 new SQLConnection(ConfigurationSettings.AppSettings("DSN_Northwind"))

Sub Page_Load(sender As Object, e As EventArgs)
Dim sqlText as String
Dim ds AS DataSet
Dim dbComm AS SQLDataAdapter
Dim sqlServer as String

If Not IsPostBack Then
sqlText = "select EmployeeID , firstname,lastname from employees"
ds = new DataSet()
dbComm = New SQLDataAdapter(sqlText,conn)
dbComm.Fill(ds,"Employees")

dbGrid.DataSource = ds.Tables("Employees").DefaultView
dbGrid.DataBind()
End if
End Sub

Function myFunc(myInt as Integer) as Boolean
If myInt >3 and myInt <7 then
Return True
Else
Return False
End if
End Function
</script>

<html>
<head>
<title></title>
</head>
<body bgcolor="#FFFFFF">
<form runat=server id=form1 name=form1>
<ASP:DataGrid id="MyDataGrid" runat="server"
BorderColor="black"
BorderWidth="1"
GridLines="none"
CellPadding="4"
Font-Name="Verdana"
Font-Size="8pt"
HeaderStyle-BackColor="#aaaadd"
AutoGenerateColumns="False"
>
<Columns>
<asp:TemplateColumn HeaderText="Quantity">
<ItemTemplate>
<asp:checkbox id="mycheckbox"
   Checked=<%# myFunc(Container.DataItem("EmployeeID") ) %> runat="server" />
</ItemTemplate>
</asp:TemplateColumn>
<asp:BoundColumn HeaderText="EmployeeID" DataField="EmployeeID"/>
<asp:BoundColumn HeaderText="firstname" DataField="firstname"/>
<asp:BoundColumn HeaderText="lastname" DataField="lastname"/>
</Columns>
</asp:DataGrid>
</form>
</body>
</html>

Web.Config file

<configuration>
<appSettings>
<add key="DSN" value="server=localhost;uid=sa;pwd=;database=aspfree">
</add>
<add key="DSN_NorthWind" value="server=localhost;
     database=Northwind;Trusted_Connection=Yes" />
</appSettings>
</configuration>

blog comments powered by Disqus
ASP CODE ARTICLES

- ASP Forms
- ASP: The Beginning
- Getting Remote Files With ASP Continued
- Inbox and Outbox Manipulation in ASP
- Relational DropDownList Using VB.NET
- Ad Tracking URL Hits
- Use ViewState to display one record per page...
- Send Email using ASP.NET formatted in HTML
- ASP File Explorer
- ASP/XML Interview questions by Srivatsan Sri...
- Pressing RETURN won't submit the form
- This shows how you get the TEXT of a combo r...
- Group Data by Adrian Forbes
- Multiple checkbox select sample
- Multiple checkbox select with all values sam...

ASP Web Hosting ASP.Net Web Hosting Windows Web Hosting
 
 
 

ASP Free Forums 
 RSS  Tutorials RSS
 RSS  Forums RSS
 RSS  All Feeds
Site Map 
Request Media Kit
Write For Us Get Paid 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
Privacy Policy 
Support 


© 2003-2012 by Developer Shed. All rights reserved. DS Cluster 8 - Follow our Sitemap
Most Popular Topics
All ASP.Net Tutorials