2

在我的一个页面中,我在 CodeBehind 中关注以重定向到另一个页面。

protected void btnEASYBRIEF_Click(object sender, EventArgs e)
        {
            Response.RedirectToRoutePermanent("../Prints/EASYBRIEF.aspx?" + grdFlights.SelectedDataKey.Value);
        }

我想将其更改为“onclientclick”事件,例如

onclientclick="window.open('../Prints/EASYBRIEF.aspx?
                     +grdFlights.SelectedDataKey.Value')"

../Prints/EASYBRIEF.aspx 之后的正确文本如何

提前致谢

4

3 回答 3

0

I would create a property to access like

Code Behind

string _selectedValue;


public string SelectedValue {

    get { return _selectedValue; }
}

Set the '_selectedValue' as your grdFlights.SelectedDataKey.Value

Then in the .aspx page you can do

var value = <%# SelectedValue%>;

onclientclick="window.open('../Prints/EASYBRIEF.aspx?' + value)"

Something to that effect.

于 2013-08-30T12:08:35.020 回答
0

Each server side button have one Client Id as well. You just have to access that element with client Id and take its value

Try the following

<script type="text/javascript">
function HandleClick()
{
   window.open('../Prints/EASYBRIEF.aspx?'+
                     +document.getElementById("<%=grdFlights.ClientId%>").Value;
}
</script>
于 2013-08-30T12:15:48.440 回答
0

你能启发这部分代码吗,这几乎是相同的要求。

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
    <script type = "text/javascript">
        function GetSelectedRow(lnk) {
            var row = lnk.parentNode.parentNode;
            var rowIndex = row.rowIndex - 1;
            var customerId = row.cells[0].innerHTML;
            var city = row.cells[1].getElementsByTagName("input")[0].value;
            alert("RowIndex: " + rowIndex + " CustomerId: " + customerId + " City:" + city);
            return false;
        }
    </script>
</head>
<body>
    <form id="form1" runat="server">
    <asp:GridView ID="gvCustomers" runat="server" AutoGenerateColumns = "false" AllowPaging = "true" OnPageIndexChanging = "PageIndexChanging">
        <Columns>
        <asp:BoundField DataField = "CustomerID" HeaderText = "CustomerID" />
        <asp:TemplateField HeaderText = "City">
            <ItemTemplate>
                <asp:TextBox ID="txtCity" runat="server" Text = '<%# Eval("City") %>'></asp:TextBox>
            </ItemTemplate>
        </asp:TemplateField>
        <asp:TemplateField>
            <ItemTemplate>
                <asp:LinkButton ID="lnkSelect" runat="server" Text="Select" CommandName = "Select" OnClientClick = "return GetSelectedRow(this)" />
            </ItemTemplate>
        </asp:TemplateField>
        </Columns>
    </asp:GridView>
    </form>
</body>
</html>

小心“return false;”这一行 最后的javascript函数非常重要

于 2013-08-30T12:19:51.953 回答