Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C# ASP.NET Gridview
i have got one gridview which consists o hyperlink in oneof 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.
 
please help me out. so ar i have tried this.
 
this is my grid view
 
<asp:GridView ID="GrdViewMyTasks" runat="server" AllowSorting="True"
AutoGenerateColumns="False" BackColor="White" BorderColor="#0061C1"
BorderStyle="None" CaptionAlign="Bottom" EmptyDataText="No Records Found"
Font-Names="Verdana" Font-Size="X-Small" ForeColor="#0061C1"
Height="179px" OnRowDataBound="GrdViewMyTasks_RowDataBound" ShowFooter="True" ShowHeaderWhenEmpty="True" Width="99%" onselectedindexchanged="GrdViewMyTasks_SelectedIndexChanged" OnRowCreated="GrdViewMyTasks_RowCreated" >
 

<asp:BoundField DataField="Gen_ID" HeaderText="SL No" ReadOnly="True"
Visible="False">

<HeaderStyle BackColor="#0061C1"
HorizontalAlign="Center" VerticalAlign="Middle" />


<asp:TemplateField HeaderText="Task Name">

<asp:Label ID="TaskName" runat="server"
Font-Names="Verdana" Font-Size="X-Small" Height="24px"
Text='<%# Eval("TaskName")%>' Width="70px">


<HeaderStyle BackColor="#0061C1" ForeColor="White" />



<asp:TemplateField HeaderText="Due Date">

<asp:Label ID="DueDate" runat="server"
Font-Names="Verdana" Font-Size="X-Small"
Height="20px" Width="70px" Text='<%# Eval("DueDate","{0:dd/MM/yyyy}")%>' DataFormatString="{0:dd/MM/yyyy}">


<HeaderStyle BackColor="#0061C1" ForeColor="White" />


<asp:TemplateField HeaderText="Description">

<asp:Label ID="Description" runat="server"
Font-Names="Verdana" Font-Size="X-Small" Height="20px" Width="90px" Text='<%# Eval("Description")%>'>


<HeaderStyle BackColor="#0061C1" ForeColor="White" />


<asp:TemplateField HeaderText="Assign By">

<asp:Label ID="AssignBy" runat="server"
Font-Names="Verdana" Font-Size="X-Small" Height="20px" Width="90px" Text='<%# Eval("AssignBy")%>'>


<HeaderStyle BackColor="#0061C1" ForeColor="White" />


<asp:TemplateField HeaderText="Status">

<asp:Label ID="Status" runat="server"
Font-Names="Verdana" Font-Size="X-Small" Height="20px" Width="90px" Text='<%# Eval("Status")%>'>


<HeaderStyle BackColor="#0061C1" ForeColor="White" />


<asp:TemplateField HeaderText="% Complete">

<asp:Label ID="PercentageComplete" runat="server"
Font-Names="Verdana" Font-Size="X-Small"
Height="20px" Width="50px" Text='<%# Eval("PercentageComplete")%>'>


<HeaderStyle BackColor="#0061C1" ForeColor="White" />


<asp:TemplateField HeaderText="View Details">

<asp:HyperLink ID="ViewDetails" runat="server" Font-Names="Verdana" Font-Size="X-Small" Height="24px"
Text="View" Width="70px" NavigateUrl="Reports.aspx" ForeColor="#0061C1" DataTextField="TaskID" DataNavigateUrlFields="TaskID" DataNavigateUrlFormatString="Reports.aspx?TaskID={0}">View


<HeaderStyle BackColor="#0061C1" ForeColor="White" />



 

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
 
LblTaskID.Text = Session["TaskID"].ToString();
LblTaskName.Text = Session["TaskName"].ToString();
LblAssignBy.Text = Session["AssignBy"].ToString();
LblDescription.Text = Session["Description"].ToString();
LblDueDate.Text = Session["DueDate"].ToString();
LblStatus.Text = Session["Status"].ToString();
LblPercentageComplete.Text = Session["PercentageComplete"].ToString();
 
DataSet rep = obj.GetReports(objc);
DataView Rprts = new DataView();
Rprts.Table = rep.Tables[0];
 
LblTaskID.Visible = false;
LblTaskName.Visible = true;
LblAssignBy.Visible = true;
LblDescription.Visible = true;
LblDueDate.Visible = true;
LblStatus.Visible = true;
LblPercentageComplete.Visible = true;
LblAssignTo.Visible = false;
Posted 26-Jun-13 2:06am
s_rao88868
Comments
s_rao88 at 26-Jun-13 7:07am
   
please repl me ... i struggling with this ting since past 2 days
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

You can use COOKIES,SESSION or QueryString to retrieve value from onr page to another page....
 
Smile | :)
  Permalink  
Comments
s_rao88 at 26-Jun-13 7:19am
   
i have used sessio thr above.. but please tell me wethr its in propr format
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

Try This....Smile | :)
 
if (e.Row.RowType == DataControlRowType.DataRow)
{
HyperLink ViewDetails = e.Row.FindControl("ViewDetails") as HyperLink;
ViewDetails.NavigateUrl = "Reports.aspx?TaskID=" + e.Row.Cells[0].Text;
}
 

Just send TaskID to another page and by reference of TaskID you can easily retrieve all information from database with the help of DataSet or DataTable....there is no need to use multiple sessions...and it is also very secure way.....Smile | :)
  Permalink  
Comments
s_rao88 at 26-Jun-13 7:33am
   
i guess u havent went through the code which i have posted ther... i have written the same code in my GridView_OnRowDataBound
Nirav Prabtani at 26-Jun-13 7:36am
   
yes same code i have paste there i just want to say,......
Just send TaskID to another page and by reference of TaskID you can easily retrieve all information from database with the help of DataSet or DataTable....there is no need to use multiple sessions...and it is also very secure way.....
s_rao88 at 26-Jun-13 7:38am
   
okie got ur point... i did it but values not getting passed .. only empty labels are displaying in another page
s_rao88 at 26-Jun-13 7:39am
   
objc.TaskID = Convert.ToInt32(Session["TaskID"]);
DataSet rep = obj.GetReports(objc);
DataView Rprts = new DataView();
Rprts.Table = rep.Tables[0];
 
LblTaskID.Visible = false;
LblTaskName.Visible = true;
LblAssignBy.Visible = true;
LblDescription.Visible = true;
LblDueDate.Visible = true;
LblStatus.Visible = true;
LblPercentageComplete.Visible = true;
LblAssignTo.Visible = false;
 

this is wat i used to display the values in anothr page
s_rao88 at 26-Jun-13 7:40am
   
GetReports is my stored procedure
 
it goes like this...
 

ALTER PROCEDURE [dbo].[GetReports]
 
@TaskID int
 
AS
 
Select TaskName, DueDate, Description, AssignBy, Status, PercentageComplete
 
From dbo.Task
 
Where TaskID = @TaskID;
s_rao88 at 26-Jun-13 7:47am
   
sir please reply me
Nirav Prabtani at 26-Jun-13 8:21am
   
When you fill DataSet Then.....
fill labels value in this manner....
 
Label1.Text=Dataset.Table[0].rows["columnName1"].toString();
Label2.Text=DataSet.Table[0].rows["columnName2"].toString();
 
whatever you want...:)
s_rao88 at 27-Jun-13 3:12am
   
its nt wrking sir... sayng dataset error
Nirav Prabtani at 27-Jun-13 3:19am
   
Give proper naming of dataset, tables and columns..... :)
Nirav Prabtani at 27-Jun-13 3:25am
   
objc.TaskID = Convert.ToInt32(Session["TaskID"]);
DataSet rep = obj.GetReports(objc);


 
LblTaskID.Text = rep.Tables[0].Rows["ColumnName"].ToString();
LblTaskName.Text = rep.Tables[0].Rows["ColumnName"].ToString();
LblAssignBy.Text =rep.Tables[0].Rows["ColumnName"].ToString();
LblDescription.Text = rep.Tables[0].Rows["ColumnName"].ToString();
LblDueDate.Text = rep.Tables[0].Rows["ColumnName"].ToString();
LblStatus.Text = rep.Tables[0].Rows["ColumnName"].ToString();
LblPercentageComplete.Text = rep.Tables[0].Rows["ColumnName"].ToString();
 

LblTaskID.Visible = false;
LblTaskName.Visible = true;
LblAssignBy.Visible = true;
LblDescription.Visible = true;
LblDueDate.Visible = true;
LblStatus.Visible = true;
LblPercentageComplete.Visible = true;
LblAssignTo.Visible = false;
s_rao88 at 27-Jun-13 3:24am
   
DataSet rep = obj.GetReports(objc);
DataView Rprts = new DataView();
Rprts.Table = rep.Tables[0];
 
LblTaskName.Text = rep.Tables[0].rows["TaskName"].ToString();
LblAssignBy.Text = rep.Tables[1].rows["AssignBy"].ToString();
 
i gave like ths but its shwing error at "rows" aftr Tables[0]
Nirav Prabtani at 27-Jun-13 3:27am
   
write Rows instead of rows....:)
s_rao88 at 27-Jun-13 3:41am
   
The best overloaded method match for 'System.Data.DataRowCollection.this[int]' has some invalid arguments
sir got this error... after making it to Rows
Nirav Prabtani at 27-Jun-13 3:47am
   
ok...i am sorry i forgot to write index of Rows,,,
just write as
LblTaskName.Text = rep.Tables[0].Rows[0]["TaskName"].ToString();
LblAssignBy.Text = rep.Tables[1].rows[0]["AssignBy"].ToString();
s_rao88 at 27-Jun-13 5:22am
   
sir its sayng tht "There is no row at position 1." but TaskName is place in row 1 in my database
Nirav Prabtani at 27-Jun-13 6:46am
   
ok check is there is any count in DataSet ot not??? by Break Point.....
s_rao88 at 27-Jun-13 7:05am
   
nothng is thr .. break point nt showing anythng else thn tht of error... im calling it thru task id so i dnt need to mention it in LblTaskID.Text = rep.Tables[0].Rows[0]["TaskID"].ToString(); rite
Nirav Prabtani at 27-Jun-13 8:05am
   
i cant get you...finaly it is working or not????
s_rao88 at 27-Jun-13 8:08am
   
its nt wrking....
s_rao88 at 27-Jun-13 9:31am
   
sir i gave count value n nw no error but im nt able to get d values at labels in my reoport page
its displayn blank labels
Nirav Prabtani at 28-Jun-13 3:41am
   
here is one example just look it....:)
 
RegistrationUser Dataservice = new RegistrationUser();
 
DataTable dtGetQuestion = Dataservice.GetQuestion(txtFotgotUsername.Text);
 

 
if (dtGetQuestion.Rows.Count > 0)
{
pnlAnswer.Visible = true;
pnlUsername.Visible = false;
lblQuestion.Text = dtGetQuestion.Rows[0]["SecurityQuestion"].ToString();
 

}

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 OriginalGriff 8,284
1 Sergey Alexandrovich Kryukov 7,407
2 DamithSL 5,614
3 Maciej Los 4,989
4 Manas Bhardwaj 4,986


Advertise | Privacy | Mobile
Web03 | 2.8.1411023.1 | Last Updated 26 Jun 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100