使用 gridview 行双击将行值发送到另一个页面

本文关键字:另一个 gridview 双击 使用 | 更新日期: 2023-09-27 18:36:11

我有一个网格视图,我绑定了系统的需求表(表名像DemandFiche)。同时,有一个 Fiche 记录详细信息表,我保留我的 Fiche 记录详细信息(表名称如 DemandFicheDetails)(我也将我的 DemandFiche 表"ID"保留在 DemandFicheDetails 表中作为"DemandFicheID"。所以这两个表之间有联系)

我想双击所选行并将用于查看所选记录详细信息的 ID 值传递到另一个页面(需求详细信息表单)。

顺便说一句,我使用 asp.net 4.5 和实体框架。

我该怎么做?谢谢。

下面是aspx代码(DemandForm.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] + "');");
        }
    }
}

使用 gridview 行双击将行值发送到另一个页面

使用 javascript 监控点击,然后简单地重定向到您需要的页面。您可以将 ID 作为 URL 的一部分传递,也可以使用 cookie 传递,例如......

使用链接按钮的 Postbackurl 属性将值发送到其他页面。

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

的解决方案,单击按钮(但不是双击)

需求形式.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);
    }

需求详细表单.aspx.cs

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

感谢您的命令和想法。