c# - GridView 中的可点击行并编辑该行

标签 c# asp.net gridview row edit

我在这里遇到关于可编辑 GridView 的问题。我想要做的是通过使用单个可点击行来替换编辑按钮功能。当我单击一行时,它应该将我转发到一个新页面以编辑这些行数据。如果不使用编辑按钮,我该如何实现?

protected void GridView1_RowCreated(object sender, GridViewRowEventArgs e)
{
    // only apply changes if its DataRow

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

        // when mouse is over the row, save original color to new attribute, and change it to highlight yellow color

        e.Row.Attributes.Add("onmouseover",
        "this.originalstyle=this.style.backgroundColor;this.style.backgroundColor='#EEFF00'");



        // when mouse leaves the row, change the bg color to its original value   

        e.Row.Attributes.Add("onmouseout",
        "this.style.backgroundColor=this.originalstyle;");            

    }
}
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
    if (e.Row.RowType == DataControlRowType.DataRow)
    {
        string abc = ((GridView)sender).DataKeys[e.Row.RowIndex].Value.ToString();
        e.Row.Attributes["onClick"] = "location.href='Default.aspx?id=" + abc + "'";
        //e.Row.Attributes["onClick"] = "location.href='Default.aspx?id=" + DataBinder.Eval(e.Row.DataItem, "CategoryID") + "'";         

        e.Row.Attributes.Add("style", "cursor:pointer;");

    }

}

最佳答案

只需将控件添加到 Default.aspx 并在 default.aspx 页面加载事件(在非回发条件下)通过 ID 检索记录并填充控件。

现在当按下提交按钮时更新记录并重定向回您的原始页面

关于c# - GridView 中的可点击行并编辑该行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6772170/

相关文章:

c# - 文本框值将显示其他文本框信息,无需单击按钮

c# - 获取非 GDI 应用程序中的插入符位置

c# - 处理数据时显示对话框

c# - 解析 XML 响应

javascript - 在gridview中调用jquery函数

c# - 如何在 LINQ to 实体表达式中使用 CreateDateTime

java - 将 Java Web 应用程序转换为 .Net

c# - 仅当在计算按钮之前单击确认按钮时,如何才能显示 lblmessage?

c# - 如何使用 C# lang 在 asp .net 中将 gridview 数据转换为 excel 表

java - Android中从web异步加载图片到gridview