Go Back  Xtreme Visual Basic Talk > Other Languages > Web Programming > removing a column during runtime


Reply
 
Thread Tools Display Modes
  #1  
Old 06-01-2006, 07:45 AM
torpkevuk's Avatar
torpkevuk torpkevuk is offline
Contributor
 
Join Date: Oct 2003
Location: Nebraska, USA
Posts: 640
Default removing a column during runtime


I have a datagrid on my web app asp.net (vb.net 2003 used to make it) connected to an MS SQL Server

I populate my datagrid like this:

Code:
Public Sub CheckForInvAdj() intRASNum = Request.QueryString("RAS") Me.ViewState("RAS") = intRASNum Dim myConnectionIT As New System.Data.SqlClient.SqlConnection(myITConnString) myConnectionIT.Open() 'Populate datagrid with all inventory adjustments for this RAS Dim dgrSQL As String = "SELECT InvAdj_id, System_id, SKU_id " ' There are some more fields, but I dont want the page to wrap dgrSQL += "FROM MyTable " dgrSQL += "WHERE Incident_id = '" & intRASNum & "' ORDER BY InvAdj_id" Dim myCommand As New System.Data.SqlClient.SqlCommand(dgrSQL, myConnectionIT) Dim myReader As System.Data.SqlClient.SqlDataReader = myCommand.ExecuteReader() Dim rowCnt As Integer = 0 If myReader.HasRows Then Do While myReader.Read() rowCnt += 1 Loop End If myReader.Close() dgrAllCom.VirtualItemCount = rowCnt If dgrAllCom.VirtualItemCount = 0 Then ' If there are no records, hide the datagrid myConnectionIT.Close() dgrAllCom.VirtualItemCount = False Exit Sub End If 'at least one record was found Dim ds As New DataSet Dim da As New System.Data.SqlClient.SqlDataAdapter(dgrSQL, myConnectionIT) da.Fill(ds, dgrAllCom.CurrentPageIndex * dgrAllCom.PageSize, dgrAllCom.PageSize, "IT_Incident_InvAdj") dgrAllCom.Visible = True dgrAllCom.DataSource = ds.Tables("MyTable") dgrAllCom.DataKeyField = "InvAdj_id" dgrAllCom.DataBind() myConnectionIT.Close() End Sub

What I want to do though, is drop the first column, which is a link to Edit each individual record.

I thought maybe the .Columns.Remove but I cant seem to get it working
any help would be appreciated

thanks
Reply With Quote
  #2  
Old 06-01-2006, 07:56 AM
wayneph's Avatar
wayneph wayneph is offline
Web Junkie

Retired Moderator
* Expert *
 
Join Date: Apr 2004
Location: D/FW, Texas, USA
Posts: 8,393
Default

Remove takes a parameter, so you would have to tell it which column to remove.
RemoveAt takes an index so it's easier to pick the first column.

Just make sure you do it before you call DataBind. If you do it after, it won't have an affect...

Code:
dgrAllCom.Columns.RemoveAt(0) dgrAllCom.Visible = True dgrAllCom.DataSource = ds.Tables("MyTable") dgrAllCom.DataKeyField = "InvAdj_id" dgrAllCom.DataBind()
__________________
-- wayne, MSSM Retired
> SELECT * FROM users WHERE clue > 0
0 rows returned
Reply With Quote
  #3  
Old 06-01-2006, 08:26 AM
torpkevuk's Avatar
torpkevuk torpkevuk is offline
Contributor
 
Join Date: Oct 2003
Location: Nebraska, USA
Posts: 640
Default

Thanks wayne, yet again you've saved me from beating my head against the wall!
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
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

Forum Jump

Advertisement:





Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
subscribe
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
subscribe
 
 
-->