1
votes

please help 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

           <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

    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

         protected void Page_Load(object sender, EventArgs e)
       {
        MTMSService obj = new MTMSService();
        DBAccess db = new DBAccess();
        {
            MTMSDTO objc = new MTMSDTO();
            {

                //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;
            }
        }
    }

and this is my stored procedure

        ALTER PROCEDURE [dbo].[GetReports]

        @TaskID int

        AS

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

        From dbo.Task

        Where TaskID = @TaskID;

please let me know where im goin wrong. im unable to get the perfect solution for this from past 1 week... its getting headache thing ..

getting error "input string is not in correct format" at commented line of reports.cs file

1
Make sure when you're navigating to the Url, the Url have value in query string. if not then debug "e.Row.Cells[0].Text" whether this is giving you correct Id. - vendettamit
yeah .. it is giving the correct ID - Suraj

1 Answers

1
votes

You're querying the database with Session["TaskId"] and you're showing task id on UI from query string. Are you sure that both are same?

I think you might want to use taks id from query string rather than session.

 objc.TaskID = Convert.ToInt32(Request.QueryString["TaskID"]);

Update -

Filter the table based on your query string

rep.Tables[0].Select(string.Format("TaskID={0}", Request.QueryString["TaskID"]));