我的gridview asp.net有问题请帮忙! [英] i have a problem with my gridview asp.net please help!!!

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

问题描述

你好,

在我的项目中,我有一个gridview,我想得到文本框中特定列的总和,但我无法访问其单元格并获取值

i认为这是因为我在GridView中使用INSERT,EDIT,DELETE的TemplateFields和FooterTemplate

是问题???我该如何解决?



i甚至无法使用此获取单元格值:



Label1.Text = GridView1.Rows [0] .Cells [0] .Text;



它适用于其他gridview而不是这一个



pleaaase help !!!!!



谢谢。

hello,
in my project , i have a gridview and i want to get the sum of a specific column in a textbox, but i'm not able to access its cells and get the values
i think that it's because of TemplateFields and FooterTemplate that i'm using to INSERT,EDIT,DELETE in my GridView
is that the problem??? and how can i solve it???

i can't even get the cell value using this:

Label1.Text = GridView1.Rows[0].Cells[0].Text;

it works for other gridview but not this one

pleaaase help!!!!!

thank you.

推荐答案

请参考下面的链接吧有很好的例子..



http://www.aspdotnet-suresh.com/2011/02/normal-0-false-false-false-en-us-x-none.html [ ^ ]





http://www.aspdotnet-suresh.com/2012/01/editupdatedelete-user-account-details.html [<一个HREF =http://www.aspdotnet-suresh.com/2012/01/editupdated elete-user-account-details.htmltarget =_ blanktitle =New Window> ^ ]
please refer below link it has nice example..

http://www.aspdotnet-suresh.com/2011/02/normal-0-false-false-false-en-us-x-none.html[^]


http://www.aspdotnet-suresh.com/2012/01/editupdatedelete-user-account-details.html[^]


试试这个..



try this ..

for (int i = 0; i < grdvtest.Rows.Count; i++)
        {
            string value= ((TextBox)grdvtest.Rows[i].Cells[1].FindControl("txtname")).Text.Trim();



}



试着拿走这样的价值



txtname是模板字段中的文本框...........

如果有任何问题请告诉


}

try to take the value in this way

txtname is the textbox inside the template field...........
if any problm pls tell


试试这个:

Try this:
int total = 0;
TextBox textbox;
foreach(GridViewRow row in GridView1.Rows)
{
   textbox = (TextBox)row.Cells[0].FindControl("name of textbox");

      int number;
      bool result = Int32.TryParse(textbox.Text.Trim(), out number);
      if (result) // if true that the textbox value is int32
      {
         total += number;
      }
}



您应该使用Int32.TryParse来验证文本框值是否为数字。

如果你期望十进制数,然后使用Decimal.TryParse方法。


You should use Int32.TryParse to validate that the textbox value is number.
If you expect decimal number, then use Decimal.TryParse method instead.


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

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