Solved

Set Gridview TemplateField value from a DataTable on Page_Load?

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

Salesforce Has Never Been Easier

Improve and reinforce salesforce training & adoption using WalkMe's digital adoption platform. Start saving on costly employee training by creating fast intuitive Walk-Thrus for Salesforce. Claim your Free Account Now

Question has a verified solution.

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

In .NET 2.0, Microsoft introduced the Web Site.  This was the default way to create a web Project in Visual Studio 2005.  In Visual Studio 2008, the Web Application has been restored as the default web Project in Visual Studio/.NET 3.x The Web Si…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…

624 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