Solved

Set Gridview TemplateField value from a DataTable on Page_Load?

Posted on 2007-04-03
3
545 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
  • 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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

ASP.Net to Oracle Connectivity Recently I had to develop an ASP.NET application connecting to an Oracle database.As I am doing it first time ,I had to solve several problems. This article will help to such developers  to develop an ASP.NET client…
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.
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…

860 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