我有一个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] + "');");
}
}
}
感谢您的意见。这很有帮助。 – Khnemu