Conditional DataGrid Item and using checkboxesUsing 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>
|
| DISCLAIMER: The content provided in this article is not warranted or guaranteed by Developer Shed, Inc. The content provided is intended for entertainment and/or educational purposes in order to introduce to the reader key ideas, concepts, and/or product reviews. As such it is incumbent upon the reader to employ real-world tactics for security and implementation of best practices. We are not liable for any negative consequences that may result from implementing any information covered in our articles or tutorials. If this is a hardware review, it is not recommended to open and/or modify your hardware. |
More ASP Code Articles More By aspfree developerWorks - FREE Tools! | As businesses grow increasingly dependent upon Web applications to provide services to customers, employees and partners, these complex applications become more difficult to secure. Although traditional security solutions protect Internet infrastructure layers, they do not guard against HTTP and HTML attacks. Many organizations that conduct security testing still deploy applications that allow attackers to manipulate their logic and wreak havoc on their business. To mitigate this risk, development and delivery teams must address Web application security throughout the lifecycle, addressing the many layers detailed in this paper. FREE! Go There Now!
| | | | This whitepaper presents the benefits of successfully introducing static analysis into your organization using IBM Rational Software Analyzer. Additionally, it identifies some common pitfalls that can hinder the effective use of static analysis tooling as well as presents 10 simple strategies designed to help you quickly realize the value of static analysis using Rational Software Analyzer. FREE! Go There Now!
| | | | Visit IBM developerWorks to download a free trial version of WebSphere Business Modeler Advanced V6.1.1, IBM’s premier business process modeling and analysis tool for business users that offers process modeling, simulation, and analysis capabilities. IBM WebSphere Business Modeler helps you visualize, understand, and document business processes for continuous improvement. FREE! Go There Now!
| | | | Visit IBM developerWorks to download a free trial version of IBM Rational Business Developer V7.1. Rational Business Developer offers rapid and simplified development of business applications and services through Enterprise Generation Language (EGL) tools, generating Java or mainframe solutions while shielding developers from technical complexities. FREE! Go There Now!
| | | | As systems increase in complexity, communication between systems and software teams becomes more and more difficult. Now, there’s a way to improve product quality and communication.<br />Read the “Model Driven Systems Development” white paper to see how. Also included in this kit are more educational white papers, customer examples, tutorials, informative Webcasts, and best practices for designing, building and managing systems.<br /> FREE! Go There Now!
| | | | Join the IBM Watchfire team for an informative discussion on techniques and best practices to proactively manage Web application security and how to effectively build application security testing into the software development lifecycle (SDLC). In this Software Delivery Platform webcast you will learn: How to better understand potential web application security vulnerabilities, best practices and how to effectively integrate application security testing into the software development lifecycle, the importance of detecting and removing software vulnerabilities during application development. FREE! Go There Now!
| | | | In this webcast, IBM Rational will discuss the importance of Web application security and will share techniques and best practices to introduce application security testing into current QA processes including: understanding common security vulnerabilities and techniques to integrate security testing with defect tracking and remediation systems in an effort to safeguard sensitive online information. FREE! Go There Now!
| | | | The discipline of assembling and delivering software is maturing beyond standard developer-centric compile/test software builds. The end-to-end software development lifecycle is emerging as the new focus moves “Beyond the Build.” Join this on demand webcast to learn about methods for streamlining software delivery and key capabilities of the IBM Rational Build Forge framework for automating build and release management in environments of any size. FREE! Go There Now!
| | | | IBM Lotus Notes 8 provides a wide range of developers the ability to provide customized, integrated user interfaces via composite applications and via custom sidebar and toolbar plug-ins. This webcast provides you with tips and techniques to use with out-of-the-box capabilities of Lotus Notes 8, and survey how you can share useful components within your own company and within a larger community. FREE! Go There Now!
| | | | Explore how Rational and WebSphere software enable enterprise documentation in SOA environments. Specifically, a new integration between IBM WebSphere® Business Modeler and IBM Rational® Method Composer software can help technical writers more easily keep enterprise operations manuals in sync with changes that are made to business processes, resulting in more accurate and timely documentation that benefits the entire enterprise. FREE! Go There Now!
| | | | All FREE IBM® developerWorks Tools! | |