Click here to Skip to main content
15,901,666 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello ,please help me with this hyperlink thing.. i got a grid view where one of the column contains hyperlink say ViewDetails. upon clicking ViewDetails it should get navigate to another page called as Reports.aspx where the page should display the grid row value of selectd column in grid view in labels. i have used row data bound event .. im getting blank labels if i click the hyperlink . i have written stored procedure to get the row values. and im calling it through KEY.. its TaskID which is an auto generated column which is invisible. depending on the key value i need to display the row values.

here are the codes

XML
<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" >

             <Columns>
             <asp:BoundField DataField="TaskID" HeaderText="SL No" Visible="False" ReadOnly="True">
          <FooterStyle BackColor="#0061C1" />
          <HeaderStyle BackColor="#0061C1" HorizontalAlign="Center" VerticalAlign="Middle" />
          <ItemStyle HorizontalAlign="Center" VerticalAlign="Middle" />
          </asp:BoundField>
          <asp:TemplateField HeaderText="Task Name">
          <ItemTemplate>
          <asp:Label ID="TaskName" runat="server"
          Font-Names="Verdana" Font-Size="X-Small" Height="24px"
          Text='<%# Eval("TaskName")%>' Width="70px"></asp:Label>
          </ItemTemplate>
          <FooterStyle BackColor="#0061C1" />
          <HeaderStyle BackColor="#0061C1" ForeColor="White" />
          <ItemStyle HorizontalAlign="Center" VerticalAlign="Middle" />
          </asp:TemplateField>
          <asp:TemplateField HeaderText="Due Date">
          <ItemTemplate>
          <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}"></asp:Label>
          </ItemTemplate>
          <FooterStyle BackColor="#0061C1" />
          <HeaderStyle BackColor="#0061C1" ForeColor="White" />
          <ItemStyle HorizontalAlign="Center" VerticalAlign="Middle" />
          </asp:TemplateField>
          <asp:TemplateField HeaderText="Description">
          <ItemTemplate>
          <asp:Label ID="Description" runat="server" Font-Names="Verdana" Font-Size="X-Small" Height="20px" Width="90px" Text='<%# Eval("Description")%>'></asp:Label>
          </ItemTemplate>
          <FooterStyle BackColor="#0061C1" />
          <HeaderStyle BackColor="#0061C1" ForeColor="White" />
          <ItemStyle HorizontalAlign="Left" VerticalAlign="Middle" />
          </asp:TemplateField>
          <asp:TemplateField HeaderText="Assign By">
          <ItemTemplate>
          <asp:Label ID="AssignBy" runat="server" Font-Names="Verdana" Font-Size="X-Small" Height="20px" Width="90px" Text='<%# Eval("AssignBy")%>'></asp:Label>
          </ItemTemplate>
          <FooterStyle BackColor="#0061C1" />
          <HeaderStyle BackColor="#0061C1" ForeColor="White" />
          <ItemStyle HorizontalAlign="Center" VerticalAlign="Middle" />
          </asp:TemplateField>
          <asp:TemplateField HeaderText="Status">
          <ItemTemplate>
          <asp:Label ID="Status" runat="server" Font-Names="Verdana" Font-Size="X-Small" Height="20px" Width="90px" Text='<%# Eval("Status")%>'></asp:Label>
          </ItemTemplate>
          <FooterStyle BackColor="#0061C1" />
          <HeaderStyle BackColor="#0061C1" ForeColor="White" />
          <ItemStyle HorizontalAlign="Center" VerticalAlign="Middle" />
          </asp:TemplateField>
          <asp:TemplateField HeaderText="% Complete">
          <ItemTemplate>
          <asp:Label ID="PercentageComplete" runat="server" Font-Names="Verdana" Font-Size="X-Small" Height="20px" Width="50px" Text='<%# Eval("PercentageComplete")%>'></asp:Label>
          </ItemTemplate>
          <FooterStyle BackColor="#0061C1" />
          <HeaderStyle BackColor="#0061C1" ForeColor="White" />
          <ItemStyle HorizontalAlign="Center" VerticalAlign="Middle" />
          </asp:TemplateField>
          <asp:TemplateField HeaderText="View Details">
          <ItemTemplate>
          <asp:HyperLink ID="ViewDetails" runat="server" Font-Names="Verdana" Font-Size="X-Small" Height="24px" Width="70px" ForeColor="#0061C1" Text="ViewDetails" NavigateUrl="Reports.aspx">View</asp:HyperLink>
          </ItemTemplate>
          <FooterStyle BackColor="#0061C1" />
          <HeaderStyle BackColor="#0061C1" ForeColor="White" />
          <ItemStyle HorizontalAlign="Center" VerticalAlign="Middle" />
        </asp:TemplateField>
        </Columns>
     </asp:GridView>



aspx.cs code
C#
protected void GrdViewMyTasks_RowDataBound(object sender, GridViewRowEventArgs e)
   {
       if (e.Row.RowType == DataControlRowType.DataRow)
       {
           HyperLink ViewDetails = e.Row.FindControl("ViewDetails") as HyperLink;
           ViewDetails.NavigateUrl = "Reports.aspx?TaskID=" + e.Row.Cells[0].Text;
       }
   }



code in reports.aspx.cs
C#
protected void Page_Load(object sender, EventArgs e)
{
MTMSService obj = new MTMSService();
DBAccess db = new DBAccess();
{
MTMSDTO objc = new MTMSDTO();
{
 int ID = 0;
 int.TryParse(Request.QueryString["TaskID"], out ID);
objc.TaskID = Convert.ToInt32(Request.QueryString["TaskID"]);
DataSet rep = obj.GetReports();
DataView Rprts = new DataView();
Rprts.Table = rep.Tables[0];


var table = rep.Tables[0];

if (table.Rows.Count > 0)
{
LblTaskID.Text = rep.Tables[0].Rows[0]["TaskID"].ToString();
LblTaskName.Text = rep.Tables[0].Rows[0]["TaskName"].ToString();
LblDueDate.Text = rep.Tables[0].Rows[0]["DueDate"].ToString();
LblDescription.Text = rep.Tables[0].Rows[0]["Description"].ToString();
LblAssignBy.Text = rep.Tables[0].Rows[0]["AssignBy"].ToString();
LblStatus.Text = rep.Tables[0].Rows[0]["Status"].ToString();
LblPercentageComplete.Text = rep.Tables[0].Rows[0]["PercentageComplete"].ToString();
}

else
{

}


LblTaskName.Visible = true;
LblAssignBy.Visible = true;
LblDescription.Visible = true;
LblDueDate.Visible = true;
LblStatus.Visible = true;
LblPercentageComplete.Visible = true;
LblAssignTo.Visible = false;
}
}
}


SQL
and this is my stored procedure

<pre lang="sql">ALTER PROCEDURE [dbo].[GetReports]

        @TaskID int

        AS

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

        From dbo.Task

        Where TaskID = @TaskID;</pre>
Posted
Updated 1-Jul-13 1:38am
v5
Comments
jaideepsinh 2-Jul-13 0:50am    
Saw you code which is on MTMSService obj = new MTMSService(); cs file i think problem is on that code.
s_rao88 2-Jul-13 1:50am    
yeah got to knw ... tht shuldnt hav been inside page load... i made it prpr nw bt no change in result...:(
s_rao88 2-Jul-13 6:56am    
thnks evrybdy i gt d solution.... was missing TaskID in gridview...

I think if you pass TaskID then you have to use querystrig here ...
I dont unserstand how can you get values in session

YOu can use Querystring as below...

C#
int ID=0;
int.TryParse(Request.QueryString["TaskID"], out ID);



then by this ID you can retrieve data from database with sp.
 
Share this answer
 
Comments
s_rao88 1-Jul-13 7:36am    
i tried ur code .. but it wasnt wrkin... im getting error nw as input string is not in correct format....
s_rao88 1-Jul-13 7:40am    
look at my code i have updated it again... in reports.cs file i have italicized and bold line which gets error sayng input string is not in correct format
Nirav Prabtani 1-Jul-13 7:45am    
try this...:)
.
.
int ID = 0;
int.TryParse(Request.QueryString["TaskID"], out ID);
objc.TaskID = ID;
DataSet rep = obj.GetReports();
DataView Rprts = new DataView();
Rprts.Table = rep.Tables[0];
.
.
s_rao88 1-Jul-13 7:51am    
thnks no error nw but if i click on othr rows in grid view im getting 1st row values in reports.cs file
Nirav Prabtani 1-Jul-13 7:53am    
OK ...you have to pass ID for getting specific data...

Try this...
.
.
int ID = 0;
int.TryParse(Request.QueryString["TaskID"], out ID);
objc.TaskID = ID;
DataSet rep = obj.GetReports(ID);
DataView Rprts = new DataView();
Rprts.Table = rep.Tables[0];
.
.
<asp:hyperlink id="ViewDetails" runat="server" font-names="Verdana" font-size="X-Small" height="24px" width="70px" forecolor="#0061C1" text="ViewDetails" navigateurl="<%# " ~="" incidentreports.aspx?taskid=" + Eval(" taskid").tostring()="" %&gt;"="" xmlns:asp="#unknown">
 
Share this answer
 
Comments
s_rao88 1-Jul-13 5:52am    
im getting output in the d Reports page now but if i click on 2nd r 3rd task its displayng only 1st task.. plz help me...

prblm is wid my code behind in reports.aspx.cs... i have updated my thread please go through wid it...
jaideepsinh 1-Jul-13 6:47am    
Sorry,But i am not understand clearly what you want to do.So please tell me clearly what you want to do in which page.
s_rao88 1-Jul-13 7:04am    
i got a grid view where one of the column contains hyperlink say ViewDetails. upon clicking ViewDetails it should get navigate to another page called as Reports.aspx where the page should display the grid row value of selectd column in grid view through labels. i have used row data bound event ..i have written stored procedure to get the row values. and im calling it through KEY.. its TaskID which is an auto generated column which is invisible. depending on the key value i need to display the row values. im getting output in the d Reports page now but if i click on 2nd r 3rd task its displayng only 1st task.. plz help me...
prblm is wid my code behind in reports.aspx.cs... i have updated my thread please go through wid it...
jaideepsinh 1-Jul-13 7:14am    
Ok, I understand. Have you tried my code which i posted. Remove you RowDataBound code and try my code.I think it should work if not then tell me what problem going on.
And check this line
objc.TaskID = Convert.ToInt32(Session["TaskID"]);
what you get at objc.TaskID every time you get same id of different.
s_rao88 1-Jul-13 8:51am    
i get same id

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900