2013-10-21 95 views
0

我有一個gridview我綁定我的系統的需求表(表名像DemandFiche)。與此同時,有一個Fiche記錄詳細信息表,我保留我的Fiche記錄詳細信息(表名稱爲DemandFicheDetails)(同時我在DemandFicheDetails表中將我的DemandFiche表「ID」保存爲「DemandFicheID」。因此,這兩個表)發送行值到另一個頁面使用gridview行雙擊

我想雙擊選定的行並傳遞ID值以查看選定記錄的詳細信息到另一個頁面(DemandsDetailForm)。

順便說一句,我使用asp.net 4.5和實體框架。

我該怎麼做?謝謝。

下面是ASPX代碼(DemandsForm.aspx):

 <div> 
    <asp:GridView runat="server" OnSelectedIndexChanged="DemandsGridView_SelectedIndexChanged" OnRowDataBound="DemandsGridView_RowDataBound" Width="1300px" AllowPaging="True" AllowSorting="True" ID="GridView1" DataSourceID="DemandsEntityDataSource" AutoGenerateColumns="False"> 
     <AlternatingRowStyle BackColor="#CCCCCC" /> 
     <SelectedRowStyle BackColor="Yellow" /> 
     <Columns> 
      <asp:BoundField DataField="ID" Visible="False" /> 
      <asp:BoundField DataField="DATE_" HeaderText="Date" Visible="True" DataFormatString="{0:dd/MM/yyyy}" /> 
      <asp:BoundField DataField="FICHENO" HeaderText="Fiche No" Visible="True" /> 
      <asp:BoundField DataField="DOCODE" HeaderText="Docode" Visible="True" /> 
      <asp:BoundField DataField="STATUS" HeaderText="Status" Visible="True" /> 
      <asp:BoundField DataField="BRANCH" HeaderText="Branch" Visible="True" /> 
      <asp:BoundField DataField="DEPARTMENT" HeaderText="Department" Visible="True" /> 
      <asp:BoundField DataField="SOURCEINDEX" HeaderText="Sourceindex" Visible="True" /> 
      <asp:BoundField DataField="FACTORY" HeaderText="Factory" Visible="True" /> 
     </Columns> 
     <EditRowStyle ForeColor="#CC3300" /> 
    </asp:GridView> 
    <asp:EntityDataSource ID="DemandsEntityDataSource" runat="server" ConnectionString="name=PmsEntities" DefaultContainerName="PmsEntities" EntitySetName="PMS_DEMANDSVIEW" EntityTypeFilter="PMS_DEMANDSVIEW"> 
    </asp:EntityDataSource> 
</div> 

這裏是後面的代碼:

public partial class DemandsForm : System.Web.UI.Page 
{ 
    public DemandsDetailForm DemandsDetailForm; 
    private PmsEntities dbContext; 

    protected void Page_Load(object sender, EventArgs e) 
    { 
     dbContext = new PmsEntities(); 
    } 

    protected void DemandsGridView_SelectedIndexChanged(object sender, EventArgs e) 
    { 

    } 

    protected void DemandsGridView_RowDataBound(object sender, GridViewRowEventArgs e) 
    { 
     if (e.Row.RowType == DataControlRowType.DataRow) 
     { 
      e.Row.Attributes.Add("OnMouseOver", "this.style.cursor = 'hand';"); 

      var selectButton = new LinkButton() 
      { 
       CommandName = "Select", 
       Text = e.Row.Cells[0].Text 
      }; 

      selectButton.Font.Underline = false; 
      selectButton.ForeColor = Color.Black; 

      e.Row.Cells[0].Controls.Add(selectButton); 
      //e.Row.Attributes["OnClick"] = Page.ClientScript.GetPostBackClientHyperlink(selectButton, ""); 
      e.Row.Attributes["onclick"] = ClientScript.GetPostBackClientHyperlink(DemandsGridView, "Select$" + e.Row.RowIndex); 

      e.Row.Attributes.Add("ondblclick", "__doPostBack('DemandsGridView','Select$" + e.Row.Cells[0] + "');"); 
     } 
    } 
} 

回答

0

使用JavaScript監視點擊,然後簡單地重定向到你所需要的頁面。您可以將ID作爲URL的一部分或使用cookie作爲例子...

+0

感謝您的意見。這很有幫助。 – Khnemu

0

使用鏈接按鈕的Postbackurl屬性可將值發送到其他頁面。

lnkRedirect.PostBackUrl = "~/MyDefault.aspx?id=" & Base64Encode(dataItem("id").Text 
0

這裏是我的解決方案,按一下按鈕(而不是雙擊)

DemandsForm.aspx.cs

 protected void detailsButton_Click(object sender, EventArgs e) 
    { 
     ids = Convert.ToString(DemandsGridView.SelectedRow.Cells[0].Text); 

     Response.Redirect("~/Demand/DemandsDetailForm.aspx?ID=" + ids); 
    } 

DemandsDetailForm.aspx.cs

DemandFicheRef = int.Parse(Request.QueryString["ID"]); 

感謝命令和想法。

相關問題