我有一个网格视图,我想将一个值从一个行单元格传递到另一个页面。基于字符串值,我可以运行一个特定的查询并填充另一个网格视图。我的问题是,当我双击该行时,它不会拾取值,但是,当我更改行单元格索引时,它会拾取该行中其他列的值。如果需要更多信息,请告诉我,谢谢。
protected void grdCowCard_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
string querystring = string.Empty;
string id = e.Row.Cells[1].Text;
//Session["selectedLactationEvent"] = "MMR";
e.Row.Attributes["ondblclick"] = string.Format("doubleClick({0})", id);
//won't pick up the value("MMR") at Row.Cells[1]
//but will pick up the value("1") at Row.Cells[0]
}
}
<script type="text/javascript">
function doubleClick(queryString) {
window.location = ('<%=ResolveUrl("LactationDetails.aspx?b=") %>' + queryString);
}
</script>
该值应基于此会话,然后用于确定使用哪种方法填充网格视图。
Session["selectedLactationEvent"] = Request.QueryString["b"].ToString();
//string test = (string)(Session["selectedLactationEvent"]);
if ((string)(Session["selectedLactationEvent"]) == "MMR")
GetExtraMMRdetails();
else if ((string)(Session["selectedLactationEvent"]) == "LAC")
GetExtraLACdetails();
else
GetExtraEBIdetails();
我没有通过双击事件,而是在gridview中添加了一个buttomfield并创建了一个OnRowCommand事件。我制作了EventID和EventType(网格视图中需要从中获取值的两列)DataKeyNames。在代码后面的OnRowCommand事件中,我获取所选行的索引,并获取该行的EventID和EventType的值。我在url中使用QueryString传递了这些值。在LactationDetails页面上,我请求查询字符串并使用值。。。
<asp:GridView ID="grdCowCard" runat="server" Width="100%"
DataKeyNames="EventID,EventType" HeaderStyle-BackColor="#008B00"
OnRowCreated="grdCowCard_RowCreated" Caption="Lactation Records"
OnRowCommand="grdCowCard_RowSelected">
<Columns>
<asp:ButtonField Text="Select" CommandName="Select"/>
</Columns>
</asp:GridView>
protected void grdCowCard_RowSelected(object sender, GridViewCommandEventArgs e)
{
if (e.CommandName == "Select")
{
int RowIndex = int.Parse(e.CommandArgument.ToString());// Current row
string id = grdCowCard.DataKeys[RowIndex]["EventID"].ToString();
string eventType1 = grdCowCard.DataKeys[RowIndex]["EventType"].ToString();
//grdCowCard.Attributes["ondblclick"] = string.Format("doubleClick({0})", id, eventType1);
//id and eventType are passed to LactationDetails page, and used to determine which
//method to use and what data to retrieve
Response.Redirect("LactationDetails.aspx?b=" + id + "&c=" + eventType1);
}
}
哺乳详细信息页面
Session["selectedMilkid"] = Request.QueryString["b"].ToString();
string selectedEventType = Request.QueryString["c"].ToString();