Querystring Display data in textbox in another asp.net page

Posted by Baijuep under ASP.NET on 4/13/2013 | Points: 10 | Views : 3646 | Status : [Member] | Replies : 2
IN MY ASP.NET+VB+ACCESS DATABASE WEB.

in a gridview there is a hyperlink field the code i used is as under

<asp:HyperLinkField
DataTextField="PNO"
HeaderText="PNO"
SortExpression="PNO"
DataNavigateUrlFields="PNO"
DataNavigateUrlFormatString="pers.aspx?PNO={0}" />



when i click in the link it directs to a page pers.aspx

in that (pers.apsx) page

there are textboxes and a gridview

in the griedview datasource i had given following code

SelectParameters>

<asp:QueryStringParameter DefaultValue="0" Name="PNO" QueryStringField="pno"
Type="String" />
</SelectParameters>
the data of that particular persons is displayed in fgridview correctly but the text box data is not diplayed.

the code used in pers.aspx.vb is as under



Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Dim PNO As String = Request.QueryString("PNO")
Dim connectString As String = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=C:\web\Wing.mdb"
Dim con As OleDbConnection = New OleDbConnection(connectString)
con.Open()
PNO = "select * from Pers WHERE ([PNO] = ?)"
Dim OleDb As New OleDbDataAdapter(PNO, con)
Dim dt As New DataSet
dt.Clear()
OleDb.Fill(dt, "PersData")
pnotxt.Text = dt.Tables("Pers").Rows(0).Item("PNO")
ranktxt.Text = dt.Tables("Pers").Rows(0).Item("SKILL")
nametxt.Text = dt.Tables("Pers").Rows(0).Item("Name")
dtsentxt.Text = dt.Tables("Pers").Rows(0).Item("DOB")
unittxt.Text = dt.Tables("PERS").Rows(0).Item("DEPOT") "
tostxt.Text = dt.Tables("PERS").Rows(0).Item("FROM")
remarktxt.Text = dt.Tables("PERS").Rows(0).Item("Remarks")
coursetxt.Text = dt.Tables("PERS").Rows(0).Item("Course")
End Sub
WHEN THE CODE FOR THE TEXT BOXES ARE ADDED THE FOLLOWING ERROR COMES

No value given for one or more required parameters.

Baiju EP


Responses

Posted by: Satyapriyanayak on: 4/13/2013 [Member] [MVP] Silver | Points: 25

Up
0
Down
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="test3.aspx.cs" Inherits="Display_related_records_gridview.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 Page</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:GridView ID="g1" runat="server" AutoGenerateColumns="false">
<Columns>
<asp:HyperLinkField HeaderText="View Details Information of Employee" DataNavigateUrlFields="empid" DataNavigateUrlFormatString="test4.aspx?details={0}" Text="Employee Details"/>
</Columns>
</asp:GridView>
</div>
</form>
</body>
</html>


test4.aspx.cs

using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Data.SqlClient;
namespace Display_related_records_gridview
{
public partial class test4 : System.Web.UI.Page
{
string strConnString = ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;
string str;
string s1;
SqlCommand com;

protected void Page_Load(object sender, EventArgs e)
{
try
{
SqlConnection con = new SqlConnection(strConnString);
con.Open();
s1 = Request.QueryString[0];
str = "select * from employee where empid='" + s1 + "'";
com = new SqlCommand(str, con);
SqlDataReader reader;
reader = com.ExecuteReader();
if (reader.Read())
{
Label1.Text = reader["empname"].ToString();
Label2.Text = reader["empaddress"].ToString();
Label3.Text = reader["empsal"].ToString();
Label4.Text = reader["empphone"].ToString();
Label5.Text = reader["empfax"].ToString();
Label6.Text = reader["empcity"].ToString();
Label7.Text = reader["empstate"].ToString();
Label8.Text = reader["empzip"].ToString();
Label9.Text = reader["emplic"].ToString();
Label10.Text = reader["empstatus"].ToString();
}
}
catch (Exception ex)
{
Response.Write(ex.Message);
}

}
}
}





If this post helps you mark it as answer
Thanks

Baijuep, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Satyapriyanayak on: 4/13/2013 [Member] [MVP] Silver | Points: 25

Up
0
Down
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="test3.aspx.cs" Inherits="Display_related_records_gridview.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 Page</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:GridView ID="g1" runat="server" AutoGenerateColumns="false">
<Columns>
<asp:HyperLinkField HeaderText="View Details Information of Employee" DataNavigateUrlFields="empid" DataNavigateUrlFormatString="test4.aspx?details={0}" Text="Employee Details"/>
</Columns>
</asp:GridView>
</div>
</form>
</body>
</html>


test4.aspx.cs

using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Data.SqlClient;
namespace Display_related_records_gridview
{
public partial class test4 : System.Web.UI.Page
{
string strConnString = ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;
string str;
string s1;
SqlCommand com;

protected void Page_Load(object sender, EventArgs e)
{
try
{
SqlConnection con = new SqlConnection(strConnString);
con.Open();
s1 = Request.QueryString[0];
str = "select * from employee where empid='" + s1 + "'";
com = new SqlCommand(str, con);
SqlDataReader reader;
reader = com.ExecuteReader();
if (reader.Read())
{
Label1.Text = reader["empname"].ToString();
Label2.Text = reader["empaddress"].ToString();
Label3.Text = reader["empsal"].ToString();
Label4.Text = reader["empphone"].ToString();
Label5.Text = reader["empfax"].ToString();
Label6.Text = reader["empcity"].ToString();
Label7.Text = reader["empstate"].ToString();
Label8.Text = reader["empzip"].ToString();
Label9.Text = reader["emplic"].ToString();
Label10.Text = reader["empstatus"].ToString();
}
}
catch (Exception ex)
{
Response.Write(ex.Message);
}

}
}
}





If this post helps you mark it as answer
Thanks

Baijuep, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response