Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 1.0 and 1.1 > ASP.NET 1.0 and 1.1 Basics
Password Reminder
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
ASP.NET 1.0 and 1.1 Basics ASP.NET discussion for users new to coding in ASP.NET 1.0 or 1.1. NOT for the older "classic" ASP 3 or the newer ASP.NET 2.0.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 1.0 and 1.1 Basics section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old November 26th, 2005, 12:54 AM
Authorized User
Join Date: Nov 2005
Location: Colombo, , Sri Lanka.
Posts: 51
Thanks: 0
Thanked 0 Times in 0 Posts
Default How to add Row dynamicaly in Datagrid

Pls give me a sampale code and advice to do it.

  #2 (permalink)  
Old November 26th, 2005, 02:01 AM
Friend of Wrox
Points: 4,332, Level: 27
Points: 4,332, Level: 27 Points: 4,332, Level: 27 Points: 4,332, Level: 27
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
Join Date: Nov 2003
Location: , NJ, USA.
Posts: 1,348
Thanks: 0
Thanked 5 Times in 5 Posts

Search on Google:


  #3 (permalink)  
Old December 7th, 2005, 08:12 PM
Friend of Wrox
Points: 2,101, Level: 18
Points: 2,101, Level: 18 Points: 2,101, Level: 18 Points: 2,101, Level: 18
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
Join Date: Jul 2003
Location: , , .
Posts: 599
Thanks: 6
Thanked 3 Times in 3 Posts

This code worked beautifully for me. It is pretty much self-explanatory.

 How to Hide a DataGrid Column Dynamically?
Author Date Of Submission User Level
Sushila D. Patel 06/01/2003 Intermediate

To hide few columns in the datagrid we can make use of the tag <asp:boundcolumn> assign the relevent values to the attributes DataField,HeaderText and set the visible property to true/false. i.e by giving
 <asp:datagrid id="DataGrid1" style="Z-INDEX: 101; LEFT: 18px; POSITION: absolute; TOP: 11px" runat="server"
<asp:BoundColumn DataField="CategoryName" HeaderText="CategoryName"></asp:BoundColumn>
<asp:BoundColumn DataField="Description" HeaderText="Description" visible="false"></asp:BoundColumn>

This technique becomes cumbersome if we need to show all except one field from the database table.So solution is query the datbase without including that field in the SQL statement or use a different way to work around with this.

In this article we'll see how to hide the columns dynamically in the Datagrid. For this snippet we would use the Categories Table from the Northwind Database. We'll hide the column Picture from the Categories Table to be displayed in the Datagrid.


Create a webform with a DataGrid control.
 <asp:DataGrid AutoGenerateColumns="False" id="DataGrid1"
style="Z-INDEX: 101; LEFT: 20px; POSITION: absolute; TOP: 12px" runat="server">

In the code behind the code is as follows:

Dim myconnection As SqlClient.SqlConnection
Dim myda As SqlClient.SqlDataAdapter
Dim ds As DataSet

myconnection = New SqlClient.SqlConnection("Server=localhost;uid=sa;p assword=;database=northwind;")
myda = New SqlClient.SqlDataAdapter("Select * from Categories", myconnection)
ds = New DataSet()
myda.Fill(ds, "AllTables")

Dim i As Integer

'To navigate through the records
For i = 0 To ds.Tables(0).Columns.Count - 1

Dim objbc As New BoundColumn()
objbc.DataField = ds.Tables(0).Columns(i).ColumnName
objbc.HeaderText = ds.Tables(0).Columns(i).ColumnName

If objbc.DataField = ds.Tables(0).Columns("Picture").ColumnName Then
objbc.Visible = False
End If

DataGrid1.DataSource = ds.Tables(0)


Hope this helps.



Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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 Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Scrollbar in row of Datagrid Except Header Row Theone84 ASP.NET 2.0 Professional 0 August 11th, 2008 12:10 AM
add new row to a table stealthdevil Access VBA 1 June 1st, 2006 11:04 AM
Manage data row by row in datagrid Dragonist Classic ASP Databases 5 July 29th, 2004 04:17 AM
add row no automatically Jane SQL Language 9 June 28th, 2004 02:11 AM

All times are GMT -4. The time now is 04:31 AM.

Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.