gridview行更新中的问题 [英] Problem in gridview row updateing

查看:75
本文介绍了gridview行更新中的问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好朋友



这是我的代码,不适用于gridview行更新

Hello friends

Here is my code which is not work for gridview row updating

protected void gdUrlDetails_RowUpdating1(object sender, GridViewUpdateEventArgs e)
{
    int id = Convert.ToInt32(gdUrlDetails.DataKeys[e.RowIndex].Value.ToString());
    // Label lblUrlId = (Label)_row.FindControl("lblUrlId");
    TextBox txtUrl = (TextBox)gdUrlDetails.Rows[e.RowIndex].FindControl("txtUrl");
    // TextBox txtTitle = (TextBox)_row.FindControl("txtTitle");
    TextBox txtTitle = (TextBox)gdUrlDetails.Rows[e.RowIndex].FindControl("txtTitle");
    objurl.UpdatedDate = Convert.ToDateTime(DateTime.Today);
    objurl.UpdatedBy = Session["session_staffuserid"].ToString();
    objurl.UrlStatus = 1;
    objurl.PageId = Convert.ToInt32(ddlPageName.SelectedValue);
    URLDetails_Data.UpdateForUrlDetails(Convert.ToInt32(id), txtUrl.Text, txtTitle.Text, objurl.UpdatedBy, DateTime.Today, objurl.UrlStatus, objurl.PageId);
    gdUrlDetails.EditIndex = -1;
}

推荐答案

USE e.Row.RowState == DataControlRowState.Edit如下图所示,你的问题可能解决了/>




USE e.Row.RowState == DataControlRowState.Edit as shown below, your problem may solve


protected void gdUrlDetails_RowUpdating1(object sender, GridViewUpdateEventArgs e)
{
 if (e.Row.RowState == DataControlRowState.Edit )
 {
int id = Convert.ToInt32(gdUrlDetails.DataKeys[e.RowIndex].Value.ToString());
    // Label lblUrlId = (Label)_row.FindControl("lblUrlId");
    TextBox txtUrl = (TextBox)gdUrlDetails.Rows[e.RowIndex].FindControl("txtUrl");
    // TextBox txtTitle = (TextBox)_row.FindControl("txtTitle");
    TextBox txtTitle = (TextBox)gdUrlDetails.Rows[e.RowIndex].FindControl("txtTitle");
    objurl.UpdatedDate = Convert.ToDateTime(DateTime.Today);
    objurl.UpdatedBy = Session["session_staffuserid"].ToString();
    objurl.UrlStatus = 1;
    objurl.PageId = Convert.ToInt32(ddlPageName.SelectedValue);
    URLDetails_Data.UpdateForUrlDetails(Convert.ToInt32(id), txtUrl.Text, txtTitle.Text, objurl.UpdatedBy, DateTime.Today, objurl.UrlStatus, objurl.PageId);
    gdUrlDetails.EditIndex = -1;
}
}









< br $>






更新:问题看起来您还将Edit Item模板列与数据绑定在一起从数据表中,当你在后面的代码中获取数据时,你没有得到用户在编辑模式下更新的更新数据,你仍然得到旧数据。如果从编辑项目模板字段中删除绑定,则代码将起作用。









Update: the problem looks like that you have also bind your Edit Item template columns with the data from data table, and when you are getting the data in the code behind you are not getting the updated data which the user updates in edit mode and u still getting the old data. If you remove the Binding from the Edit Item Template fields then your code will work.


这篇关于gridview行更新中的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆