Solved

Gridview - Row ---> Detailsview

Posted on 2006-12-01
1
2,259 Views
Last Modified: 2012-05-05
When click Select on Gridview. I want the selected row to display on Detailsview on the same page. When I clicked Edit on Detailsview, I got this error "The Detailsview 'DetailsView1' fired event ModeChanging which wasn't handled."


Imports System.Data.SqlClient
Imports System.Data
Imports System.Web.Configuration

Partial Class Practice1
    Inherits System.Web.UI.Page

   
    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load


        Dim cnstr As String = WebConfigurationManager.ConnectionStrings("TEST").ConnectionString
        Dim cn As New SqlConnection(cnstr)
        Dim cmdstr As String = "select ID,TDATE, CITY, ZIPCODE STATE from residence"
        Dim ad As New SqlDataAdapter(cmdstr, cn)
        Dim ds As New DataSet

        ad.Fill(ds, "table1")
        Me.GridView1.DataSource = ds.Tables("table1")
        Me.GridView1.DataBind()



    End Sub


    Protected Sub GridView1_RowCommand(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewCommandEventArgs) Handles GridView1.RowCommand


        Dim index As Integer = Convert.ToInt32(e.CommandArgument)    
        Dim row As GridViewRow = Me.GridView1.Rows(index)
        Dim ID As String = row.Cells(1).Text

        Dim cnstr As String = WebConfigurationManager.ConnectionStrings("TEST").ConnectionString
        Dim cn As New SqlConnection(cnstr)
        Dim cmdstr As String = "select ID,TDATE, CITY, ZIPCODE STATE from residence where id =" & ID
        Dim ad As New SqlDataAdapter(cmdstr, cn)
        Dim ds As New DataSet

        ad.Fill(ds, "table1")

        Me.DetailsView1.DataSource = ds.Tables("table1")
        Me.DetailsView1.DataBind()



    End Sub

    Protected Sub GridView1_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles GridView1.SelectedIndexChanged

        DetailsView1.ChangeMode(DetailsViewMode.ReadOnly)

    End Sub
0
Comment
Question by:VBdotnet2005
1 Comment
 
LVL 6

Accepted Solution

by:
DonKyles earned 500 total points
ID: 18059340
This is a good source for you. It has example and contains code in VB and C#.

http://quickstarts.asp.net/QuickStartv20/aspnet/doc/ctrlref/data/detailsview.aspx

This site will help you to fix the problem
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

One of the pain points with developing AJAX, JavaScript, JQuery, and other client-side behaviors is that JavaScript doesn’t allow for cross domain request for pulling content. For example, JavaScript code on www.johnchapman.name could not pull conte…
In an ASP.NET application, I faced some technical problems. In this article, I list them out and show the solutions that I found.  I hope it will be useful. Problem: After closing a pop-up window, the parent page should be refreshed automaticall…
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…

830 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question