在更新查询的gridview中检索值 [英] Retriving a value in a gridview in an update query

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

问题描述

你好,


我有一个要求,我要根据复选框字段选择的行数来更新gridview中的值.


//可变的decleratins

Hello ,


I have a requirement in which i am updating values in a gridview based upon no of rows selected by the checkbox field.


//Variable Decleratins

for(int index =0;index<dt1.Rows.Count;index++)
               {
                   CheckBox chkselect = (CheckBox)grdReplicate.Rows[index].FindControl("chkSelect");
                   if (chkselect.Checked == true)
                   {
                       if (res == "")
                       {
                           lblppo=(Label)grdReplicate.Rows[index].FindControl("lblgrdppono");
                           res = Convert.ToString(grdReplicate.DataKeys[index].Value);
                           ppoids = lblppo.Text;
                       }
                   }



LblMsg = Penobj._ExecuteQuery("update t_replicate_detail set MICR_CODE =""+(grdReplicate.Rows [index] .Cells [8] .Text)+"其中Replicate_ID in(""+ res +"'')");



但是我无法在gridview中检索特定的单元格值.如何解决?



LblMsg = Penobj._ExecuteQuery("update t_replicate_detail set MICR_CODE=''" + (grdReplicate.Rows[index].Cells[8].Text)+ " '' where Replicate_ID in( ''" + res + "'')");



But Iam not able to retrive the particular cell value in the gridview.How to go about it?

推荐答案

网格视图不会自动与数据库同步.它与数据源的内存缓存同步.您正在更新数据库并不意味着gridview已更新.您需要刷新(查询数据库并检索数据)数据源并重新绑定网格视图.

通常,更改会先影响数据源,然后再更新数据库.例如,将首先更新数据集,然后调用数据适配器的update方法或更新linq上下文对象,然后Submit Changes方法将同步所有必要的内容.在您的情况下,您将直接将值更新到数据库.因此,您需要对其进行检索并在更新后绑定到gridview.

另一件事,您的方法Penobj._ExecuteQuery进行更新.我猜它调用了ExecuteNonQuery,它不会返回任何东西.所以我怀疑你会在这里得到任何东西LblMsg =

遵循数据从控件传递到数据库并返回到gridviews数据源的方式.如果它卡在某个地方,则可以在此处发布.我们的专家很乐意为您提供帮助.
Grid view is not automatically sync with database. It is sync with the in memory cache of the datasource. You are updating the database doesn''t mean the gridview got updated. You need to refresh (query database and retrieve data) the datasource and rebind the grid view.

Generally changes affect the data source first,before it update the database. For example a dataset will be updated first and then call the data adapter''s update method or update a linq context object and the the submit changes method sync all necessary things. In your case you are directly updating the values to the database. So you need to retrieve it and bind to the gridview after updated.

Another thing, your method Penobj._ExecuteQuery doing a update. I guess it calls an ExecuteNonQuery which will not return back anything. So I doubt you will get anything here LblMsg =

Follow the ways the data travel from control to database and come back to the gridviews datasource. if it stuck somewhere you may post here. Our experts will be happy to help you.


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

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