griedview文本框中的更新在编辑模式下传递旧值 [英] update in griedview text box passes old value in edit mode

查看:108
本文介绍了griedview文本框中的更新在编辑模式下传递旧值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我的gridview更新事件的代码。在编辑模式下我更改文本框中的值仍然会传递旧值..





 protected void SubCategoryGrid_RowUpdating(object sender,GridViewUpdateEventArgs e)
{
string scn;
int catid;
int scatid = Convert.ToInt32(((Label)(SubCategoryGrid.Rows [e.RowIndex] .FindControl(scidlbl)))。Text);
TextBox box1 =(TextBox)SubCategoryGrid.Rows [e.RowIndex] .FindControl(txteditscatname);
TextBox txt2 =(TextBox)SubCategoryGrid.Rows [e.RowIndex] .FindControl(txteditcatid);

scn = box1.Text;
catid = Convert.ToInt32(txt2.Text);
d.editsubcategory(scn,scatid,catid);
SubCategoryGrid.EditIndex = -1;
FILLSUBCATGRID();
}

解决方案

我在编辑模式下更改文本框中的值后仍旧过去值..

这通常发生在事件引发之前再次重新绑定网格时。要处理/避免它,请确保在页面属性IsPostback中包装了datagrid数据绑定代码。

  if (!IsPostback)
{
// gridview1.Datasource
// gridview.Databind()
}


this is my code for gridview update event.after i change value in text box in edit mode still it passes old value..


protected void SubCategoryGrid_RowUpdating(object sender, GridViewUpdateEventArgs e)
       {
           string scn;
           int catid;
           int scatid = Convert.ToInt32(((Label)(SubCategoryGrid.Rows[e.RowIndex].FindControl("scidlbl"))).Text);
           TextBox box1 = (TextBox)SubCategoryGrid.Rows[e.RowIndex].FindControl("txteditscatname");
           TextBox txt2 = (TextBox)SubCategoryGrid.Rows[e.RowIndex].FindControl("txteditcatid");

           scn = box1.Text;
           catid = Convert.ToInt32(txt2.Text);
           d.editsubcategory(scn, scatid,catid);
           SubCategoryGrid.EditIndex = -1;
           FILLSUBCATGRID();
       }

解决方案

after i change value in text box in edit mode still it passes old value..
This generally happens when you rebind the grid again before the event is raised. To handle/avoid it, make sure you have wrapped your datagrid databind code within page property IsPostback.

if(!IsPostback)
{
  // gridview1.Datasource
  // gridview.Databind()
}


这篇关于griedview文本框中的更新在编辑模式下传递旧值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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