ASP.NET - 使用Javascript在文本框中选择和显示Gridview行数据

时间:2015-01-10 03:41:33

标签: javascript c# jquery asp.net

目前,我有一个工作代码,用于在文本框中选择和传输gridview行数据。这是代码

 protected void grdRP_SelectedIndexChanged(object sender, EventArgs e)
    {

        GridViewRow row = grdLocation.SelectedRow;
        hdnSearchedLoc.Value = grdLocation.Rows[grdLocation.SelectedIndex].Cells[1].Text;
        txtSearchedLoc.Text = HttpUtility.HtmlDecode(row.Cells[2].Text);


    }

当它是本地的时,它在功能和性能(速度)方面很有效。当我将其上传到网络服务器时,我已经看到了速度上的差异。在将行数据传输到文本框之前需要5秒或更长时间。

现在,我正在考虑使用javascript来提高速度的另一种方法,因为它是在客户端。我看过一个示例代码,但它仅适用于选择方法,但行数据的传输仍然是相同的速度。这是代码

的javascript

function setMouseOverColor(element)
{
    oldgridSelectedColor = element.style.backgroundColor;
    element.style.backgroundColor='#C0C0C0';
    element.style.cursor='hand';
    //element.style.textDecoration='underline';
}

function setMouseOutColor(element)
{
    element.style.backgroundColor=oldgridSelectedColor;
    element.style.textDecoration='none';
}

aspx.cs

 protected void grdRP_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        e.Row.Cells[0].Style["display"] = "none";

        if (e.Row.RowType == DataControlRowType.DataRow)
        {

            e.Row.Attributes["onmouseover"] =
                "javascript:setMouseOverColor(this);";
            e.Row.Attributes["onmouseout"] =
                "javascript:setMouseOutColor(this);";

            e.Row.Attributes["onclick"] =
            Page.ClientScript.GetPostBackClientHyperlink
                (this.grdRP, "Select$" + e.Row.RowIndex);


        }
    }

还有其他javascript方式吗?

0 个答案:

没有答案
相关问题