Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Visual Basic > VB.NET 1.0 > VB.NET 2002/2003 Basics
|
VB.NET 2002/2003 Basics For coders who are new to Visual Basic, working in .NET versions 2002 or 2003 (1.0 and 1.1).
Welcome to the p2p.wrox.com Forums.

You are currently viewing the VB.NET 2002/2003 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 January 21st, 2005, 04:25 PM
Authorized User
 
Join Date: Jun 2003
Posts: 16
Thanks: 0
Thanked 0 Times in 0 Posts
Default Edit/Add/Delete within a DataGrid

Hello


   I'm using the following codes to Edit the data locatedin the datagrid.

  
Code:
Private Sub DataGridItemsonHold_EditCommand(ByVal source As Object, _
Code:
    ByVal e As System.Web.UI.WebControls.DataGridCommandEventArgs) _
    Handles DataGridItemsonHold.EditCommand

        DataGridItemsonHold.EditItemIndex = e.Item.ItemIndex
        DataGridItemsonHold.DataBind()

    End Sub



   Now when I use the above codes is Add a textbox to all the column on the selected Item.

Edit Column1 Column2

Edit textbox1 TextBox2


Now what I would like to know is their a way to just Enable one Column instead of the Two??? Let Say I only wanted the user to Edit the column2 and Column1 would not be Editable. How could i make this work???


 Thanks
__________________
Thanks

Sincerely; Oscar Martinez
 
Old January 21st, 2005, 11:37 PM
Friend of Wrox
 
Join Date: Dec 2004
Posts: 307
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to Vadivel Send a message via Yahoo to Vadivel
Default

Set ReadOnly as true for those columns which you don't want to edit. I guess you might need to check DataGridColumnStyle class.

Best Regards
Vadivel

MVP ASP/ASP.NET
http://vadivel.thinkingms.com
 
Old January 22nd, 2005, 02:57 AM
Authorized User
 
Join Date: Jun 2003
Posts: 16
Thanks: 0
Thanked 0 Times in 0 Posts
Default



Can you please give me an Example on how to set to the specific column to ReadOnly. Thanks

Thanks

Sincerely; Oscar Martinez
 
Old January 22nd, 2005, 12:01 PM
Friend of Wrox
 
Join Date: Dec 2004
Posts: 307
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to Vadivel Send a message via Yahoo to Vadivel
Default

I am @ home at present .. I don't have .NET installed here. The earliest I could send you a sample would be on Monday IST. Sure somebody else would in the meantime help you out with the code snippet.

Best Regards
Vadivel

MVP ASP/ASP.NET
http://vadivel.thinkingms.com
 
Old January 22nd, 2005, 05:41 PM
Authorized User
 
Join Date: Jun 2003
Posts: 16
Thanks: 0
Thanked 0 Times in 0 Posts
Default


  First of all Thanks for your reply.


 I don't mean to be a A**hole but why wouln't you have Visual Studio at Home???

Thanks

Sincerely; Oscar Martinez
 
Old January 23rd, 2005, 01:17 AM
Authorized User
 
Join Date: Jun 2003
Posts: 16
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hello


   Well after reading books and doing some research I finnaly got it working. First I right click on my DataGrid and select Property Builder. Then I select Column and added a Bound Column to my Datagrid. Over here is where you name your columns, So lets says you have a table with the following columns FName,LName. On the bound column you just add FName WHERE it says Data Field and FName where is says Header text, Next add another bound column and Type in LName in the data field and type in LName in the header text. Now we are ready to Connect to tha database and Bind the data to the Datagrid.



Add the following IMPORTS

Code:
Imports System.Data
Imports System.Data.Common
Imports System.Data.SqlClient
Imports System.Data.SqlDbType
Imports System.Data.SqlTypes

This is where i conect to my Database

Code:
Dim MyConnection As SqlConnection = New SqlConnection("server='YourComputerName\Your InstanceName';initial catalog='YourDatabase';user id=UserID;password='Password';")
Dim MyDataAdapter As New SqlDataAdapter
Dim MyDataset As New DataSet
Now Bind the Data to your DataGrid

 'Bind the Data to the Data Grid
               
Code:
MyDataAdapter.SelectCommand = New SqlCommand
Code:
                MyDataAdapter.SelectCommand.Connection = MyConnection
                MyDataAdapter.SelectCommand.CommandText = "Select * From UserInfo"
                MyConnection.Open()
                MyDataAdapter.SelectCommand.ExecuteScalar.ToString()
                MyConnection.Close()
                MyDataAdapter.Fill(MyDataset, "UserInfo")

                Me.DataGridItemsonHold.DataSource = MyDataset
                Me.DataGridItemsonHold.DataBind()




Thanks

Sincerely; Oscar Martinez





Similar Threads
Thread Thread Starter Forum Replies Last Post
how to EDIT,delete,add,items in my database zedekiah BOOK: Beginning ASP 3.0 2 May 15th, 2008 08:16 AM
How to edit/delete list items through SPGridView meera SharePoint Development 0 December 7th, 2007 11:32 AM
save, edit, and delete sime_tyres VB Databases Basics 1 September 1st, 2006 09:45 PM
Edit or Delete records tsimsha Classic ASP Basics 6 October 30th, 2004 03:26 AM
Edit/Delete ButtonColumn not working planoie ASP.NET 1.0 and 1.1 Professional 9 August 30th, 2004 07:39 AM





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