gridview wid hyperlink not displaying

Posted by Su88rao under C# on 6/27/2013 | Points: 10 | Views : 1151 | Status : [Member] | Replies : 3
i have a gridview which consists of hyperlink in one of the column (called as view details) upon clicking that hyperlink, the details of particular row of that grid view should display in a labels of another page(reports.aspx) .
please help me out. so far i have tried this.
this is my grid view


</asp:TemplateField>
<asp:TemplateField HeaderText="View Details">
<ItemTemplate>
<asp:HyperLink ID="ViewDetails" runat="server" Font- Names="Verdana" Font-Size="X-Small" Height="24px" Text="View" Width="70px" NavigateUrl="Reports.aspx" ForeColor="#0061C1" DataTexField="ID" DataNavigateUrlFields="TaskID" DataNavigateUrlFormatString="Reports.aspx?TaskID={0}">View</asp:HyperLink>
</ItemTemplate>
<FooterStyle BackColor="#0061C1" />
<HeaderStyle BackColor="#0061C1" ForeColor="White" />
<ItemStyle HorizontalAlign="Center" VerticalAlign="Middle" />
</asp:TemplateField>
</Columns>
</asp:GridView>
this is my code behind for grid view on row data bound

if (e.Row.RowType == DataControlRowType.DataRow)
{
HyperLink ViewDetails = e.Row.FindControl("ViewDetails") as HyperLink;
ViewDetails.NavigateUrl = "Reports.aspx?TaskID=" + e.Row.Cells[0].Text;
}
here is my code behind or reports.aspx where the details of the grid view should be displayed
protected void Page_Load(object sender, EventArgs e)
{
MTMSService obj = new MTMSService();
DBAccess db = new DBAccess();
{
MTMSDTO objc = new MTMSDTO();
{
objc.TaskID = Convert.ToInt32(Session["TaskID"]);
DataSet rep = obj.GetReports(objc);
DataView Rprts = new DataView();
Rprts.Table = rep.Tables[0];
LblTaskName.Visible = true;
LblAssignBy.Visible = true;
LblDescription.Visible = true;
LblDueDate.Visible = true;
LblStatus.Visible = true;
LblPercentageComplete.Visible = true;
LblAssignTo.Visible = false;
}
}
}

stored procedure

ALTER PROCEDURE [dbo].[GetReports]

@TaskID int

AS

Select TaskName, DueDate, Description, AssignBy, Status, PercentageComplete

From dbo.Task

Where TaskID = @TaskID;




Responses

Posted by: Satyapriyanayak on: 6/27/2013 [Member] [MVP] Silver | Points: 25

Up
0
Down
test3.aspx

<%@ 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:BoundField HeaderText="Employee name" DataField="empname"/>
<asp:BoundField HeaderText="Employee Salary" DataField="empsal"/>
<asp:BoundField HeaderText="Employee Address" DataField="empaddress"/>

<asp:HyperLinkField HeaderText="View Details Information of Employee" DataNavigateUrlFields="empid" DataNavigateUrlFormatString="test4.aspx?details={0}" Text="Employee Details"/>
</Columns>
<HeaderStyle ForeColor="#FF0066" />
<AlternatingRowStyle ForeColor="#CC6600" />
</asp:GridView>
</div>
</form>
</body>
</html>




test3.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 test3 : System.Web.UI.Page
{
string strConnString = ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;
string str;

SqlCommand com;

protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
bindgrid();
}
}
private void bindgrid()
{
SqlConnection con = new SqlConnection(strConnString);
con.Open();
str = "select * from employee";
com = new SqlCommand(str, con);
SqlDataReader reader;
reader = com.ExecuteReader();
g1.DataSource = reader;
g1.DataBind();
con.Close();
}
}
}



If this post helps you mark it as answer
Thanks

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

Posted by: Satyapriyanayak on: 6/27/2013 [Member] [MVP] Silver | Points: 25

Up
0
Down
test4.aspx



<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="test4.aspx.cs" Inherits="Display_related_records_gridview.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 Page</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<table border="1" style="border-collapse: collapse" cellspacing="1">
<tr>
<td width="77" height="16" align="left" ><b><font size="2" color="red">Empname:</font></b></td>
<td width="77" height="16" align="left" ><b><font size="2">&nbsp;<asp:Label ID="Label1" runat="server" Font-Bold="True"></asp:Label><br /></font></b></td>
</tr>
<tr>
<td width="77" height="16" align="left" ><b><font size="2" color="red">Empaddress:</font></b></td>
<td width="77" height="16" align="left" ><b><font size="2">&nbsp;<asp:Label ID="Label2" runat="server" Font-Bold="True"></asp:Label><br /></font></b></td>
</tr>
<tr>
<td width="77" height="16" align="left" ><b><font size="2" color="red">Empsal:</font></b></td>
<td width="77" height="16" align="left" ><b><font size="2">&nbsp;<asp:Label ID="Label3" runat="server" Font-Bold="True"></asp:Label><br /></font></b></td>
</tr>

</table>
</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();

}
}
catch (Exception ex)
{
Response.Write(ex.Message);
}

}
}
}


If this post helps you mark it as answer
Thanks

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

Posted by: Su88rao on: 6/27/2013 [Member] Starter | Points: 25

Up
0
Down
sir thanks for ur reply .. but im using 3 layered architecture and i cant get my connection string on my code behind... and even my database... and ur code looks similar to mine... so i request u to give some suggestions to alter my code

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

Login to post response