Click here to Skip to main content
15,918,343 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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:

C#
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
Posted
Updated 1-Aug-12 17:55pm
v2

You need to bind the CheckBox you just added to something meaningful. Make sure that you are binding it correctly.
 
Share this answer
 
Hi,
It sounds like you are using CheckBoxField and you have assigned a DataField property to it. Try this:
ASP.NET
<asp:templatefield headertext="Check" xmlns:asp="#unknown">                            
    <itemtemplate>
        <asp:checkbox id="chkIndicator" runat="server" />
    </itemtemplate>
</asp:templatefield>


--Amit
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900