homepage Welcome to WebmasterWorld Guest from 174.129.76.87
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Pubcon Platinum Sponsor 2014
Home / Forums Index / Microsoft / Microsoft IIS Web Server and ASP.NET
Forum Library, Charter, Moderators: ocean10000

Microsoft IIS Web Server and ASP.NET Forum

    
VB.NET DataGrid to ASP.NET
Kavkan

5+ Year Member



 
Msg#: 3399 posted 4:52 am on May 12, 2006 (gmt 0)

Hi everyone,

I wrote a Windows VB.NET application that uses SQL Server 2000. The application displays database records in a Data Grid element.

I would like to turn this into a Web application, and again, use Data Grid to display the records in the browser.

I have it working properly using a List Box element, but when I use the Data Grid nothing is displayed.

Am I missing some parameters, declarations or..?

 

macrost

10+ Year Member



 
Msg#: 3399 posted 6:32 am on May 12, 2006 (gmt 0)

Can you paste the code that you are having problems with? It would be a lot easier to help you with this.

Kavkan

5+ Year Member



 
Msg#: 3399 posted 8:07 am on May 12, 2006 (gmt 0)

Inherits System.Web.UI.Page
Dim connstr As String = "data source=SERVER;initial catalog=DB;user id=USER;password=PASSWORD;"
Dim sqlStr As String = "SELECT * FROM Users"
Dim dt As New DataTable

Private Sub btnLoad_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnLoad.Click
dt.Clear()
Dim dataAdapter As New SqlClient.SqlDataAdapter(sqlStr, connstr)
dataAdapter.Fill(dt)
dataAdapter.Dispose()
dgDisplay.DataSource = dt
End Sub

Private Sub btnSave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSave.Click
Dim changes As Integer
Dim dataAdapter As New SqlClient.SqlDataAdapter(sqlStr, connstr)
Dim commandBuilder As New SqlClient.SqlCommandBuilder(dataAdapter)
changes = dataAdapter.Update(dt)
dataAdapter.Dispose()
If changes > 0 Then
MsgBox(changes & " changed rows were stored in the database.")
Else
MsgBox("no changes made.")
End If
End Sub

TheNige

10+ Year Member



 
Msg#: 3399 posted 9:44 pm on May 12, 2006 (gmt 0)

I believe you need to databind the datasource.

dgDisplay.Databind

Kavkan

5+ Year Member



 
Msg#: 3399 posted 11:51 pm on May 12, 2006 (gmt 0)

Thanks Nige! It displays the records properly, but it doesn't allow for direct editing of a particular record through the Data Grid.

Is it possible to make the Web Application Data Grid identical to the Windows Application Data Grid(ie. to have the same functionality)?

If so, would it require a change in the code or is it a configuration of the Data Grid element's parameters?

macrost

10+ Year Member



 
Msg#: 3399 posted 12:47 pm on May 15, 2006 (gmt 0)

Well one thing that you would have to do is add a textbox control or whatever you want to the datagrid. (I don't have vs.net 2003 installed on this computer, sorry) Then you would iterate through all the items of the datagrid on save click.
Datagrid Iteration [xmlpitstop.com] has a good expample on how to do that.

I was looking at the code, and at the bottom when the example shows how to use the findcontrol method, I like to use DirectCast instead of the older CType, it is a bit faster, IMO.

TheNige

10+ Year Member



 
Msg#: 3399 posted 8:25 pm on May 15, 2006 (gmt 0)

I suggest doing a search on the web for 4GuysFromRolla web site. They have something like a 17 part tutorial for the DataGrid control.

The web control is similar in name to the Forms control, but they are a little different in what they do and how it works.

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Microsoft / Microsoft IIS Web Server and ASP.NET
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved