Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / ASP.NET / General / August 2007

Tip: Looking for answers? Try searching our database.

How to dynamically add control to datagrid item template

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Chris Fink - 20 Aug 2007 18:36 GMT
I am trying to dynamically add a control within an itemtemplate container in
a gridview and need some assistance.  

For example, my goal is to evaluate a column's value in a datagrid row and
depending on it's value dynamically add a few hyperlink controls to within
the template field.  

I'm familiar with doing this in .NET 1.1 using the itemondatabound event and
interrogating the datagrid and am looking for a similiar way to do this with
the dataview, ideally all in a similiar event.

Any help is appreciated!

                   <asp:TemplateField HeaderText="Converted FileName"
SortExpression="ConvertedFileName">
                       <ItemTemplate>
                           <asp:Label ID="lblConvertedFileName"
runat="server" Text='<%# Bind("ConvertedFileName") %>'></asp:Label>
                           <br />
                           <asp:HyperLink ID="hlDownloadCFN" runat="server"
NavigateUrl="~/Admin/Admin_Bundles.aspx" Text="Download"></asp:HyperLink>
                           <br />
                           <asp:HyperLink ID="hlViewCFN" runat="server"
NavigateUrl="~/Admin/Admin_Bundles.aspx" Text="View"></asp:HyperLink>
                           <br />
                           <asp:HyperLink ID="hlUploadCFN" runat="server"
NavigateUrl="~/Admin/Admin_Bundles.aspx" Text="Upload"></asp:HyperLink>
                           <br />
                           <asp:HyperLink ID="hlDeleteCFN" runat="server"
NavigateUrl="~/Admin/Admin_Bundles.aspx" Text="Delete"></asp:HyperLink>
                       </ItemTemplate>
                   </asp:TemplateField>
Manish Bafna - 21 Aug 2007 05:04 GMT
Hi,
Now in gridview instead of ItemDataBound there is RowDataBound event.You can
something like this:
<asp:GridView ID="clients_gridview" runat="server"
AutoGenerateColumns="False"
               DataSourceID="LinqDataSource1" AllowSorting="True"
               onrowdatabound="GridView1_RowDataBound">
And then in GridView1_RowDataBound write something like this:
HyperLink hl = (HyperLink)e.Row.FindControl("nameofhyperlink");
hl.NavigateUrl =  "yoururl";
Or try this:
((HyperLink)e.Row.Cells[1].Controls[0]).NavigateUrl = "yoururl";
RowDataBound event fires when data is explicitly bound to data web control.
Also you would find site http://gridviewguy.com/ pretty useful.
Signature

Hope this helps.
Thanks and Regards.
Manish Bafna.
MCP and MCTS.

> I am trying to dynamically add a control within an itemtemplate container in
> a gridview and need some assistance.  
[quoted text clipped - 28 lines]
>                         </ItemTemplate>
>                     </asp:TemplateField>

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.