C# 双击时使用Request.QueryString传递值

C# 双击时使用Request.QueryString传递值,c#,asp.net,gridview,request.querystring,rowdatabound,C#,Asp.net,Gridview,Request.querystring,Rowdatabound,我有一个gridview,我想把一个值从一个行单元格传递到另一个页面。基于字符串的值,我可以运行一个特定的查询并填充另一个gridview。 我的问题是,当我双击行时,它不会拾取值,但是,当我更改行单元格索引时,它会拾取行中其他列的值。 如果需要更多信息,请告诉我,谢谢 protected void grdCowCard_RowDataBound(object sender, GridViewRowEventArgs e) { if (e.Row.RowType == DataContr

我有一个gridview,我想把一个值从一个行单元格传递到另一个页面。基于字符串的值,我可以运行一个特定的查询并填充另一个gridview。 我的问题是,当我双击行时,它不会拾取值,但是,当我更改行单元格索引时,它会拾取行中其他列的值。 如果需要更多信息,请告诉我,谢谢

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>

我没有双击事件,而是在gridview中添加了一个buttomfield,并创建了一个OnRowCommand事件。我创建了EventID和EventType(gridview中需要从中获取值的两列)DataKeyName。 在代码隐藏中,在OnRowCommand事件中,我获取所选行的索引,并获取该行上EventID和EventType的值。我使用url中的查询字符串传递了这些值。在LaxtionDetails页面上,我然后请求查询字符串并使用值

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

无论如何,使用
switch((string)Session[“selectedLastionEvent”])case“MMR”:{}…
ASP.Net页面不会捕获双击事件。您必须在Javascript中通过从客户端调用代码来实现这一点我正在用Javascript实现这一点
<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();