GridView中的问题 [英] Problem in GridView

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

问题描述

大家好,
我有一个gridview,我想从中获取一个参数以将其传递给插入函数.
我尝试了这段代码,但出现了异常

Hi all,
I have a gridview and I want to take a parameter from it to pass it to an insert function.
I tried this code but I get an exception

string accountname = ((TextBox)GridView2.Rows[j].Cells[0].Controls[0]).Text; 
insert_ReadyMade_Mobil(Int64.Parse(cmb_Subgroupmobiles.SelectedValue.ToString()), Id.ToString());


谁能帮我,请注意,我在运行时填充了gridview.
谢谢,


Can any one help me please, and notice that I fill the gridview in the runtime.
Thanks

推荐答案

好像无法找到GridView&中的文本框.在您的第一行本身上引发异常.要在ASP.net中的Gridview中访问文本框,您需要使用FindControl在其中查找文本框并将其转换为TextBox.

Looks like,it''s not able to find out the textbox inside the GridView & throwing exception at your first line itself.To acess textbox inside a Gridview in ASP.net, you need to use FindControl to find the textbox inside and cast it to TextBox.

foreach (GridViewRow row in GridView2.Rows)
    {


     string accountname = ((TextBox)row.FindControl("TextBox1")).Text;

    }


看看这篇文章

访问GridView控件内的不同控件 [


Check out this article

Accessing the different controls inside a GridView control[^]

Hope this helps!


首先,您正在检索称为accountname的内容,但是在检索之后,我看不到您下一步将在哪里使用它陈述.

其次,我将在第二行中执行此操作:

First, you''re retrieving something you call accountname, but after retrieving it, I don''t see where you''re using it in the next statement.

Second, I would do this for the 2nd line:

Int64 value;
if (Int64.TryParse(cmb_Subgroupmobiles.SelectedValue.ToString(), out value)
{
    insert_ReadyMade_Mobil(value, ID.ToString());
}
else
{
    // display an error message?
}






以下是我的代码中的一个有效示例:
Heres a working example from my code:
lblMaxCreditJourneys->Text = gridPassenger->Rows[e->RowIndex]->Cells[this->dgMaxCreditJourneys->Name]->Value->ToString();



它的C ++/CLI.更改->到 .您将获得C#



Its C++/CLI. Change -> to . and you will have C#


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

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