Wrox Programmer Forums
|
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 software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old November 26th, 2005, 12:54 AM
Authorized User
 
Join Date: Nov 2005
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.

MSB
__________________
MSB
 
Old November 26th, 2005, 02:01 AM
Friend of Wrox
 
Join Date: Nov 2003
Posts: 1,348
Thanks: 0
Thanked 5 Times in 5 Posts
Default

Search on Google:

http://www.dotnet247.com/247referenc.../16/80550.aspx

 
Old December 7th, 2005, 08:12 PM
Friend of Wrox
 
Join Date: Jul 2003
Posts: 599
Thanks: 6
Thanked 3 Times in 3 Posts
Default

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


Introduction:
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"
AutoGenerateColumns="False">
<Columns>
<asp:BoundColumn DataField="CategoryName" HeaderText="CategoryName"></asp:BoundColumn>
<asp:BoundColumn DataField="Description" HeaderText="Description" visible="false"></asp:BoundColumn>
</Columns>
</asp:datagrid>


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.

Snippet:

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">
</asp:DataGrid>

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.Columns.Add(objbc)
DataGrid1.DataSource = ds.Tables(0)
DataGrid1.DataBind()
Next

http://www.c-sharpcorner.com/Code/20...ridColDyna.asp

Hope this helps.

Richard







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





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