Gridview更新问题? [英] Gridview updation problem?

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

问题描述

protected void GVVAC_RowUpdating(object sender, GridViewUpdateEventArgs e)
   {
       DataTable dt = new DataTable();
       int st = Convert.ToInt32(GVVAC.DataKeys[e.RowIndex].Values[0].ToString());
       TextBox txtage1 = (TextBox)GVVAC.Rows[e.RowIndex].FindControl("txtage");
       TextBox txtvaccinename1 = (TextBox)GVVAC.Rows[e.RowIndex].Cells[3].Controls[1];
       TextBox txtadmin1 = (TextBox)GVVAC.Rows[e.RowIndex].Cells[4].Controls[1];
       TextBox txtdose1 = (TextBox)GVVAC.Rows[e.RowIndex].Cells[5].Controls[1];

       breederdailypl.Age = Convert.ToInt32(txtage1.Text.ToString());
       breederdailypl.vaccine = txtvaccinename1.Text.ToString();
       breederdailypl.admin = txtadmin1.Text.ToString();
       breederdailypl.dose = txtdose1.Text.ToString();



       breederdailypl.Snum = st;
       dt = breederdailybal.updatevaccine(breederdailypl);
       //chkHatchdetails = objhatcheryBAL.updateHatchMasterdet(objhatcheryPL);
       ScriptManager.RegisterClientScriptBlock(this.Page, this.GetType(), "UpdateDetails", "alert('Update Successful');", true);
       GVVAC.EditIndex = -1;

       grid();





   }




$ b当我编辑文本框并输入新值时,$ b

,但新值不会出现在文本框中...。请帮助我




when i edit the textbox and enter the new value ,but new value is not come to the textbox... .please help me

推荐答案

我认为页面加载你绑定网格..





并忘记检查 IsPostBack





请检查....
I Think On Page Load You Bind Grid..


And Forgot to Check IsPostBack.


Please Check....


我建​​议您使用Bind代替在模板字段中使用Eval绑定。



MSDN参考。



http://msdn.microsoft.com/en-us/library/ms178366.aspx [ ^ ]



此外,尝试按照Anudeep的建议检查Ispostback条件。





希望这有帮助......
I would suggest you to use Bind instead of using Eval binding in your template field .

MSDN reference for this .

http://msdn.microsoft.com/en-us/library/ms178366.aspx[^]

Also , try to check the Ispostback condition as Anudeep suggested.


Hope this helps...


5月你是在page_load上的某个地方填充网格。

问题出现在这里,当你点击更新按钮页面获得回发时,在你的update_eventhandler page_load执行之前,它会将你的网格刷新为以前的值。现在,当你执行

更新事件时,它获取的数据与网格从数据库中得到的值相同。

你可以做什么只需将以下代码放入你的页面加载



如果(!Page.Ispostback)

{

//从这里调用填充网格方法

}



希望这会有所帮助!!!
May be you are filling grid somewhere on page_load.
The problem arises from here, when you click on update button page gets postback and before your update_eventhandler page_load executes it refreshes your grid to previous values. Now when your
update event executes it gets same values which grid is getting from database.
what you can do just put following code in your page load

if(!Page.Ispostback)
{
//call fill grid method from here
}

hope this helps!!!


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

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