would it be possible to do it like this?
<asp:TemplateField HeaderText="Export" Visible='<%# Bind("isExported") %>'>
</asp:TemplateField>
I tried it and I got this problem:
The TemplateField control with a two-way databinding to field deviceExport must have an ID
You should use <%# Eval("isExported")%> instead of <%# Bind("isExported")%>
Related
When binding a datasource to a Repeater control, is it possible to databind to the ID property of a server-side control inside the ItemTemplate? like so:
<asp:Repeater ID="rptToolTips" runat="server">
<ItemTemplate>
<telerik:RadToolTip ID="tt<%# Eval("Name") %>" ClientIDMode="Static" runat="server">
<div class="tip">
<div class="segName">Segment #<%# Eval("Name") %></div>
<div>Flow:<%# Eval("Flow", "{0:N}") %></div>
</div>
</telerik:RadToolTip>
</ItemTemplate>
</asp:Repeater>
...here I'm trying to set the RadToolTip's ID property to "tt[name-value]". I've tried a few variants but they're invalid:
ID="tt<%# Eval("Name") %>"
ID='tt<%# Eval("Name") %>'
ID="tt<%# Eval('Name') %>"
It's not possible. A server control's ID is set at the time it's being created or at design time. Once it's set you cannot reset it during the data binding.
But, if you are trying to use this ID value in JQuery or JavaScript you could employ the following hack.
Add a custom property to your control (give it any name you like and in this case I'll use myId)
myId='<%# Eval("Name") %>'
No you can find this element by this myId property
Hope this helps.
Try this to assign ID
ID=' "tt" + <%# Eval("Name") %>'
Also see this answer by me to one of the questions at SO for another way (using pure JavaScript's this object rather than using a custom property to get the clientID) of doing this.
Just thought of keeping these linked for future reference.
I can't find any answer anywhere. I want to refer to the row object itself in an databinding expression in a gridview, like this:
<asp:TemplateField HeaderText="Description">
<ItemTemplate>
<asp:Label runat="server"
Text = '<%# GetPendingReason(Eval("this")) %>' />
</ItemTemplate>
</asp:TemplateField>
But it doesn't work because "this" doesn't refer to any attribute. Referencing individual attributes works fine, but how do you refer to the current row?
Simply use <%# Container.DataItem %>. Do not use Databinder.
If you want to refer to the current row you do that at codebehind using
GridViewRow row = GridView1.Rows[index];
at any of the GridView event.
I have the following repeater code:
<asp:Repeater ID="repMain" runat="server" OnItemCommand="repMain_ItemCommand" EnableViewState="false">
<ItemTemplate>
<dmg:testcontrol runat="server" MyData=<%#Container.DataItem %>>
</dmg:testcontrol>
</ItemTemplate>
</asp:Repeater>
The testcontrol usercontrol looks like:
<%# Control Language="C#" AutoEventWireup="true" CodeBehind="TestControl.ascx.cs" Inherits="TestRepeater.TestControl" %>
<asp:Literal runat="server" ID="litMain" Text="<%#MyData.MyValue %>"></asp:Literal>
<asp:DropDownList runat="server" ID="dropdownMain"></asp:DropDownList>
<asp:Button runat="server" ID="btnMain" Text="Click Me" CommandName="Update" CommandArgument="<%#dropdownMain.SelectedValue%>"/>
Is it possible for me to send through the dropdownMain.SelectedValue as the CommandArgument?
Just now it is an empty string.
Thanks
Duncan
PS This is related to ASP.NET Repeater not binding after ItemCommand but I thought the two sufficiently different to keep apart.
A bit old question but I just my self found the answer to this one.
CommandArgument="<%#dropdownMain.SelectedValue%>"
Needs to look like this instead with single quotes! All inline codes within a asp.net controls have to be done this way instead.
CommandArgument='<%#dropdownMain.SelectedValue%>'
Why not get the selected value, and use it inside the Command function ?
(why to try to send it as argument, from the moment you can get it inside the command called function and its the same)
I have a nested repeater and i want to pass value in its header. Here is my code so far..
The main problem is the id of the control in header template is also coming from code behind.
<asp:Repeater ID="RptrProgCategory" runat="server">
<ItemTemplate>
<asp:Repeater ID="RptrPrograms" runat="server">
<HeaderTemplate><input type="hidden" id="<%= questvalue%>"/></HeaderTemplate>
<ItemTemplate>
<%# DataBinder.Eval(Container.DataItem, "cat") %>
</ItemTemplate>
</asp:Repeater>
</ItemTemplate>
</asp:Repeater>
I want value in questvalue from code behind. Any idea how to achieve this?
Edit: I wanted to put this value in a DataTable and bind that value in Repeater bcoz i want output like this may be <%# DataBinder.Eval(Container.DataItem, "questvalue") %> instead of <%= questvalue%>..but in tht case i am not able to find the control
Category1(id of hidden field )
subcat1
subcat2
subcat3
Category2(id of hidden field)
subcat4
subcat5..and so on..
Repeater mainRepeater = this.Page.FindControl("RptrProgCategory") as Repeater;
Repeater nestedRepeater = mainRepeater.FindControl("RptrProgCategory") as Repeater;
You can then do a FindControl in nestedRepeater for questValue.
Add a runat='server' to questvalue so that you can access it in code behind.
I am writing this from memory, syntax might not be correct but it should get you off in the right direction.
set the id of the control in the repeater to something like mycontrolId - and then on OnItemDataBound - (or even OnItemCreated) use findcontrol("mycontrolId") - and then change the id of the control to your questvalue param.
I have a gridview with a hyperlink inside an TemplateField. The NavigateUrlFormat will be populated from the Web.Config file, it has the following format:
mysite.com/{0}
Where {0} will be populated from the gridview datasource, however, my current code doesn't work:
<asp:TemplateField HeaderText="WorkOrder #">
<ItemTemplate>
<asp:HyperLink ID="HyperLink1" runat="server"
NavigateUrl='<%# Eval("WorkOrderKey", "<%$ AppSettings:DispatchLink %>") %>'
Text='<%# Eval("WorkOrderKey") %>'></asp:HyperLink>
</ItemTemplate>
</asp:TemplateField>
The problem is right after "AppSettings:DispatchLink", it closes the tag when it see "%>". Is there a way around this problem?
Thank you,
Kenny.
You cannot nest <%# and other tags. Use ConfigurationManager.AppSettings["DispatchLink"] (pls. lookup correkt Class/Property in MSDN) instead.
Or: If your are using that HyperLink Control more than once I would suggest that you create an own MYHyperLink derived from System.Web.UI.WebControls.HyperLink and set the Property NavigateUrlFormatString in your Constructor.
Something like this:
public class DispatchLink : System.Web.UI.WebControls.HyperLink
{
public DispatchLink()
{
this. NavigateUrlFormatString = ConfigurationManager.AppSettings["DispatchLink"]
}
}