1

请帮助解决这个超链接的事情.. 我有一个网格视图,其中一列包含超链接,比如 ViewDetails。单击 ViewDetails 后,它应该导航到另一个名为 Reports.aspx 的页面,该页面应在标签的网格视图中显示所选列的网格行值。我使用了行数据绑定事件。如果我单击超链接,我会得到空白标签。我已经编写了存储过程来获取行值。我通过 KEY 调用它。它的 TaskID 是一个自动生成的不可见的列。根据我需要显示行值的键值。

这是代码

           <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 代码

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

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

这是我的存储过程

        ALTER PROCEDURE [dbo].[GetReports]

        @TaskID int

        AS

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

        From dbo.Task

        Where TaskID = @TaskID;

请让我知道我哪里出错了。从过去的 1 周开始,我无法为此找到完美的解决方案……这让人头疼……

在reports.cs 文件的注释行中出现错误“输入字符串格式不正确”

4

1 回答 1

1

您正在使用 Session["TaskId"] 查询数据库,并且您正在从查询字符串的 UI 上显示任务 ID。你确定两者是一样的吗?

我认为您可能想使用查询字符串中的 taks id 而不是会话。

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

更新 -

根据您的查询字符串过滤表

rep.Tables[0].Select(string.Format("TaskID={0}", Request.QueryString["TaskID"]));
于 2013-07-01T07:40:14.303 回答