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>
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. -- Hope this helps. Thanks and Regards. Manish Bafna. MCP and MCTS. "Chris Fink" wrote: > 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>