I'm working on a Web page on ASP.NET 3.5 and want to display data from GRIDVIEW when there is only one column
Each line is a kind of menu link to displayed data on another GRIDVIEW in the page.
the GRIDVIEW information should be used as a menu I can not make the records function as buttons so the second gridview will change data when you click on one.
The code I use is:
|
It's really urgent for me I'll be happy to receive any help!
Satyapriya NayakPosted Apr 24, 2010, 11:40 AM
I have done two webpages test3.aspx and test4.aspx.
First create a table employee with two columns empid,empname respectively
Test3.aspx.vb code:-
Imports System.Data
Imports System.Data.SqlClient
Partial Class test3
Inherits System.Web.UI.Page
Dim strConnString As String = System.Configuration.ConfigurationManager.ConnectionStrings.Item("ConnectionString").ToString()
Dim con As New SqlConnection(strConnString)
Dim str As String
Dim com As SqlCommand
Dim sqlda As SqlDataAdapter
Dim ds As DataSet
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
bind()
End Sub
Sub bind()
con.Open()
str = "select * from employee"
com = New SqlCommand(str, con)
Dim reader As SqlDataReader
reader = com.ExecuteReader()
g4.DataSource = reader
g4.DataBind()
con.Close()
End Sub
End Class
Its html code test3.aspx:-
<%@ Page Language="VB" AutoEventWireup="false" CodeFile="test3.aspx.vb" Inherits="test3" %>
DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Untitled Pagetitle>
head>
<body>
<form id="form1" runat="server">
<div>
<asp:gridview id="g4" runat="server" AutoGenerateColumns="false" >
<columns>
<asp:hyperlinkfield headertext="Empid" datatextfield="empid" datanavigateurlformatstring="test4.aspx?details={0}" datanavigateurlfields="empid"/>
<asp:boundfield headertext="Empname" datafield="empname" />
columns>
asp:gridview>
div>
form>
body>
html>
Test4.aspx code:-
Imports System.Data
Imports System.Data.SqlClient
Partial Class test4
Inherits System.Web.UI.Page
Dim strConnString As String = System.Configuration.ConfigurationManager.ConnectionStrings.Item("ConnectionString").ToString()
Dim con As New SqlConnection(strConnString)
Dim str As String
Dim com As SqlCommand
Dim sqlda As SqlDataAdapter
Dim ds As DataSet
Dim s1 As String
Dim dt As DataTable
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Try
con.Open()
s1 = Request.QueryString(0)
str = "select * from employee where empid='" + s1 + "'"
com = New SqlCommand(str, con)
g5.DataSource = com.ExecuteReader
g5.DataBind()
Catch ex As Exception
MsgBox(ex.Message)
End Try
con.Close()
End Sub
End Class
Its html code test4.aspx
<%@ Page Language="VB" AutoEventWireup="false" CodeFile="test4.aspx.vb" Inherits="test4" %>
DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Untitled Pagetitle>
head>
<body>
<form id="form1" runat="server">
<div>
div>
<asp:GridView ID="g5" runat="server">
asp:GridView>
form>
body>
html>
Dipa AhujaPosted Apr 24, 2010, 8:24 AM