2013-06-26 21 views
2

我有一個網格視圖,其中一列中的超鏈接(稱爲視圖的細節)組成的超鏈接,點擊該超鏈接,具體細節該網格視圖的行應顯示在另一個頁面(reports.aspx)的標籤中。網格視圖行包含超鏈接,一旦點擊它應該顯示值在另一頁的特定行

請幫我一把。到目前爲止,我已經嘗試過。

這是我網格視圖

 <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="Gen_ID" HeaderText="SL No"    ReadOnly="True" Visible="False"> 
          <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" 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> 

這是我的代碼背後必然

 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是格柵的細節視圖應顯示

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

存儲過程

   ALTER PROCEDURE [dbo].[GetReports] 

       @TaskID int 

       AS 

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

      From dbo.Task 

      Where TaskID = @TaskID; 

回答

1

好我使用的GridView代替標籤,以顯示超鏈接d值。所以這裏是它

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; 
     } 
     if (e.Row.RowType == DataControlRowType.DataRow) 
     { 
      ((Label)e.Row.Cells[0].FindControl("Description")).Attributes.Add("style", "word-break:break-all;word-wrap:break-word"); 
     } 
    } 

protected void GrdViewMyTasks_RowCommand(object sender, GridViewCommandEventArgs e) 
    { 
     if (e.CommandName == "cmdLink") 
     { 
      string TaskID = Convert.ToString(e.CommandArgument.ToString()); 
      Response.Redirect("Reports.aspx?TaskID=" + TaskID); 
     } 
    } 

ASPX代碼:

<asp:TemplateField HeaderText="View Details"> 
<ItemTemplate> 
    <asp:HyperLink ID="ViewDetails" runat="server" DataNavigateUrlFields="TaskID" 
    DataNavigateUrlFormatString="Reports.aspx?TaskID={0}" Font-Names="Verdana" 
    Font-Size="X-Small" ForeColor="Red" Font-Bold="true" Height="30px" Width="100px" 
    NavigateUrl="Reports.aspx" Text="ViewDetails" >View</asp:HyperLink> 
</ItemTemplate> 
<FooterStyle BackColor="LightSlateGray" /> 
<HeaderStyle BackColor="LightSlateGray" ForeColor="White" Width="90px" /> 
<ItemStyle HorizontalAlign="Center" VerticalAlign="Middle" /> 
</asp:TemplateField> 
2

替換此

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

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

得到這個錯誤(輸入字符串的不正確的格式) – Suraj

+0

聽起來像 「的TaskID」那麼不是一個數字。 – Tim

+0

它是一個數字..將分享我的數據,如果需要 – Suraj

相關問題