Solved

Set Gridview TemplateField value from a DataTable on Page_Load?

Posted on 2007-04-03
3
547 Views
Last Modified: 2012-06-27
Hey,

I'm using a gridview to display data from a database but I want to do this programmatically and with using templatefields.

I set up the gridview (FileManagerGrid) with the following columns:
                    <Columns>
                        <asp:TemplateField HeaderText="Select">
                            <EditItemTemplate>
                                <asp:CheckBox ID="SelectCheckBox" runat="server" />
                            </EditItemTemplate>
                            <ItemTemplate>
                                <asp:CheckBox ID="SelectCheckBox" runat="server" />
                            </ItemTemplate>
                        </asp:TemplateField>
                        <asp:TemplateField HeaderText="File/FolderID" Visible="False">
                            <EditItemTemplate>
                                <asp:Label ID="FileFolderIDLabel" runat="server" />
                            </EditItemTemplate>
                            <ItemTemplate>
                                <asp:Label ID="FileFolderIDLabel" runat="server" />
                            </ItemTemplate>
                        </asp:TemplateField>
                        <asp:TemplateField HeaderText="File/Folder">
                            <EditItemTemplate>
                                <asp:TextBox ID="FileFolderNameTextB" runat="server" />
                            </EditItemTemplate>
                            <ItemTemplate>
                                <asp:TextBox ID="FileFolderNameTextB" runat="server" />
                            </ItemTemplate>
                        </asp:TemplateField>
                        <asp:TemplateField HeaderText="IsFolder" Visible="False">
                            <EditItemTemplate>
                                <asp:CheckBox ID="IsFolderCheckBox" runat="server" />
                            </EditItemTemplate>
                            <ItemTemplate>
                                <asp:CheckBox ID="IsFolderCheckBox" runat="server" />
                            </ItemTemplate>
                        </asp:TemplateField>
                    </Columns>

I have the values stored in a DataTable which I get on Page_Load but I don't know how to set the values of the templatefield's with their relevant value in the DataTable.
0
Comment
Question by:rebels_mascot
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 18

Accepted Solution

by:
Elvio Lujan earned 500 total points
ID: 18843513
dim chk as checkbox = gridview.findcontrol("IsFolderCheckBox")

if..... then
chk.checked=true
end if
0
 
LVL 18

Expert Comment

by:Elvio Lujan
ID: 18843523
do it into a for each...

for each r as gridviewrow in gridview.rows
dim chk as checkbox = r.findcontrol("IsFolderCheckBox")

if..... then
chk.checked=true
end if

next
0
 

Author Comment

by:rebels_mascot
ID: 18844645
Thanks for the quick reply,

I've done the following

        int i = 0;

        foreach (DataRow r in FileFolderTable.Rows)
        {
            FileManagerGrid.
            ((Label)FileManagerGrid.Rows[i].FindControl("FileFolderIDLabel")).Text =
                r["FileFolderID"].ToString();
            ((Label)FileManagerGrid.Rows[i].FindControl("ParentFolderIDLabel")).Text =
                r["ParentFolderID"].ToString();
            ((TextBox)FileManagerGrid.Rows[i].FindControl("FileFolderNameTextB")).Text =
                r["FileFolderName"].ToString();
            ((TextBox)FileManagerGrid.Rows[i].FindControl("FileDescriptionTextB")).Text =
                r["Description"].ToString();
            ((Label)FileManagerGrid.Rows[i].FindControl("FileTypeLabel")).Text =
                r["DateUploaded"].ToString();
            ((Label)FileManagerGrid.Rows[i].FindControl("FileSizeLabel")).Text =
                r["Title"].ToString();
            ((Label)FileManagerGrid.Rows[i].FindControl("DateLabel")).Text =
                r["FileType"].ToString();
            ((CheckBox)FileManagerGrid.Rows[i].FindControl("IsFolderCheckBox")).Checked =
                Boolean.Parse(r["IsFolder"].ToString());

            i++;

in Page_Load, but I need to insert a row first. I'm not sure how to do this? Is there any Gridview.Insert type of function?
0

Featured Post

Enroll in June's Course of the Month

June's Course of the Month is now available! Every 10 seconds, a consumer gets hit with ransomware. Refresh your knowledge of ransomware best practices by enrolling in this month's complimentary course for Premium Members, Team Accounts, and Qualified Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction This article shows how to use the open source plupload control to upload multiple images. The images are resized on the client side before uploading and the upload is done in chunks. Background I had to provide a way for user…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
Come and listen to Percona CEO Peter Zaitsev discuss what’s new in Percona open source software, including Percona Server for MySQL (https://www.percona.com/software/mysql-database/percona-server) and MongoDB (https://www.percona.com/software/mongo-…
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…

728 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question