GridView运行时错误 [英] Run time error with gridview

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

问题描述

我已经成功地使用目录中的所有文件填充了一个gridview控件.现在我在gridview控件中添加了一个新的复选框库伦.但是当我运行代码时,出现此错误...
在所选数据源上找不到名称为"chkfile"的字段或属性"
关于它的任何建议.我该如何解决.使用Visual Studio 2010的即时消息

继承人代码:

I have successfully populated a gridview control wiht all the files from the directory.Now I have added a new checkbox coulum in the gridview control..but when i run the code i get this error...
"A field or property with the name ''chkfile'' was not found on the selected data source"
Any suggestions on it.How can i solve it.IM using visual studio 2010

heres the code:

protected void showfiles()
{
    string[] filePaths = Directory.GetFiles(Server.MapPath("~/NewFolder1/"));
    List<listitem> files = new List<listitem>();
    foreach (string filePath in filePaths)
    {
        files.Add(new ListItem(Path.GetFileName(filePath), filePath));
    }
    GridView1.DataSource = files;
    GridView1.DataBind();
}



谢谢



Thanks

推荐答案

您需要将刚添加的CheckBox绑定到有意义的东西上.确保正确绑定它.
You need to bind the CheckBox you just added to something meaningful. Make sure that you are binding it correctly.



听起来您正在使用CheckBoxField,并且已为其分配了DataField属性.试试这个:
Hi,
It sounds like you are using CheckBoxField and you have assigned a DataField property to it. Try this:
<asp:templatefield headertext="Check" xmlns:asp="#unknown">                            
    <itemtemplate>
        <asp:checkbox id="chkIndicator" runat="server" />
    </itemtemplate>
</asp:templatefield>



--Amit



--Amit


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

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