DataBinding: 'System.Data.DataRowView' does not contain a property with the name - asp.net

I'm adding data using footer template and I have button to add. So when I try to add
error 'System.Data.DataRowView' does not contain a property with the name '
It shows error in this line:
<asp:TemplateField ItemStyle-Width = "30px" HeaderText ="Name">
<FooterTemplate>
<ItemTemplate>
<asp:Label ID="lblMembershipName" runat="server" width ="150px"
Text='<%# Eval"MembershipName")%>'> </asp:Label**>
</ItemTemplate>
</FooterTemplate>
</asp:TemplateField>

You should change: Text='<%# Eval"MembershipName")%>' to Text='<%# Eval("MembershipName")%>'
You where missing the opening ( of the Eval function.

The problem looks to be in your binding statement assuming your code is as you posted and not a copy typo:
<asp:Label ID="lblMembershipName" runat="server" width ="150px"
Text='<%# Eval"MembershipName")%>'> </asp:Label**>
Your missing a bracket as it should be:
<asp:Label ID="lblMembershipName" runat="server" Width="150px"
Text='<%# Eval("MembershipName") %>' />
Also verify that what you are binding to has a field called MembershipName.

You've ommited a (, it should be:
Eval("MembershipName") instead of Eval"MembershipName").
And instead of </asp:Label**> you should write </asp:Label>.

Sounds like you are trying to databind data in the footer - ensure you have nothing that looks like this in the footer section - posting the code would help loads.
text = '<%#....
Ross

Related

Trouble setting label text property with Eval

Does any of you know why this is not possible?
<asp:Label ID="lblWordSes" Font-Bold="True" EnableViewState="True" ViewStateMode="Enabled" runat="server" Text="<%# string.Format(Eval("Word1").ToString()) %>"></asp:Label>
i am trying to set the text value with data from the database but i can get this to work.
In the Text attribute you need to do like that:
Text="<%# string.Format("{0}",Eval("Word1").ToString()) %>">

How to use Substring in Bind text

I am binding a Gridview with some data and I have taken labels in template field and I am binding the data to that label's text property,
<asp:TemplateField HeaderText="Proceedings" SortExpression="PROCEEDINGS" ItemStyle-Width="60px">
<ItemTemplate>
<asp:Label ID="lblProceedings" runat="server" CssClass="Label_Value" Text='<%# Bind("PROCEEDINGS") %>' ToolTip='<%# Bind("PROCEEDINGS") %>'></asp:Label>
</ItemTemplate>
<ItemStyle Wrap="true" HorizontalAlign="Left" />
I want the length of the Bound text till 10 characters how to achieve this
Try this:
<asp:Label ID="lblProceedings" runat="server" CssClass="Label_Value" Text='<%# Eval("PROCEEDINGS") == null ? "empty" : Eval("PROCEEDINGS").ToString().Substring(0,10)%>'
or check this link Substring in a label
I hope that help.
10Label has no MaxLangth property, you can use here textbox and give MaxLength="10", and style it as a lable.
EDIT:
You can use substring like this:
<asp:label id="lDesc" runat ="server" text ='<%# (Eval("Description") .Length>=10) ? Eval("Description").SubString(0,10) :Eval("Description") %>'></asp:Label>
You can use like this
Text='<%# Eval("PROCEEDINGS").ToString().Substring(0,9) %>'
Or you can write a function in .cs file like this.
protected getString(string str)
{
return (str..Substring(0,9));
}
And use this in gridview label as
Text='<%# getString(Eval("PROCEEDINGS").ToString()) %>'

How to Split comma seperate DataItem field in GridView Eval?

here my code-
<asp:TemplateField HeaderText="HIGH RISK (10-12)" ItemStyle-HorizontalAlign="Center">
<ItemTemplate>
<asp:Label ID="lblHighrisk" runat="server" Text='<%# Eval("URANGE").ToString().Split('-')[0] %>' />
</ItemTemplate>
</asp:TemplateField>
but that is giving compile time error 'Server tag is not well formed'
Perhaps you have a problem with the quotation marks in the second split?
try
Text='<%# Eval("URANGE").ToString().Split("-")[0] %>'
does that help?
Update after comment
Yes, that makes sense
Try reversing the quotation in that case
Text="<%# Eval'URANGE').ToString().Split('-')[0] %>"
does that help?
Try it without quotes:
<asp:Label ID="lblHighrisk" runat="server"
Text=<%# Eval("URANGE").ToString().Split('-')[0] %> />
It will be ok when you convert string "." to char and post it to split method.
Text='<%# Eval("costIntegerPart").ToString().Split(Convert.ToChar("."))[0] %>'
This will work
style='<%#Eval("cssHover").ToString().Split(new string[]{";"},StringSplitOptions.None)[0]%>'

Gridview : Hyperlink and description in the same column cell

Apologies for the newbie question. My client wishes me to make a small change to the gridview on his http://www.flogitdonegal.com/SearchPage.aspx page.
Note the way the Title column is a hyperlink to view more information. This comes from a 'BriefDescription' field in the database.
How can I add 250 chars from the 'FullDescription' underneath the Title in the same cell, but I dont want it be a hyperlink.
Essentially it will be 2 fields coming into the same column.
Thanks in advance for all help.
John
If this is using a GridView you are most likely using a TemplateField as it is to display the HyperLink.
Within the ItemTemplate of the TemplateField you can specify an additional Label underneath using something as follows:
<asp:Label runat="server" id="FullDescLabel" Text='<%# DataBinder.Eval(Container.DataItem, "FullDescription") %>' />
You need to use the TemplateField and here is a tutorial that explains some of the other fields that GridView offers as well.
<asp:GridView ID="gvwCompounds" runat="server" DataSourceID="objItemsFromYourDB">
<Columns>
....
<asp:TemplateField>
<ItemTemplate HeaderText="Title">
<asp:HyperLink runat="server" ID="Hperlink1" NavigateUrl='<%# Eval("BriefDescriptionUrl") %>' Text='<%# Eval("BriefDescription") %>' />
<br />
<asp:Label runat="server" ID="Label1" Text='<%# Eval("FullDescription") %>' />
</ItemTemplate>
</asp:TemplateField>
....
</Columns>
</asp:GridView>

How do you concatenate text when using Bind expression in asp.net

What is the syntax to concatenate text into a binding expression for an asp.net webpage (aspx).
For example if I had a hyperlink that was being bound like this:
<asp:HyperLink id="lnkID" NavigateUrl='<%# Bind("Link") %>' Target="_blank"
Text="View" runat="server"/>
How do you change, say, the Text to concatenate a bound value with a string? Variations like this aren't quite right.
Text='<%# Bind("ID") + " View" %>'
neither does
Text='<%# String.Concat(Bind("ID"), " View") %>'
Use Eval instead.
Text='<%# Eval("ID", "{0} View") %>'
Eval is also better if the value is not going to be updated, where Bind allows two way data binding.
You can also place the "concatenation" in the text portion of a tag if using a template field:
<asp:TemplateField HeaderText="Name" SortExpression="sortName">
<ItemTemplate>
<asp:LinkButton ID="lbName" runat="server" OnClick="lbName_Click" CommandArgument='<%# Eval("ID") %>'>
<%--Enter any text / eval bindind you want between the tags--%>
<%# Eval("Name") %> (<%# Eval("ID") %>)
</asp:LinkButton>
</ItemTemplate>
This results in output like:
Name (ID)
inside of the template column.
I have used String.Format("{0}{1}"... before to good effect.
You could use the following:
CommandArgument='<%#String.Format("{0}|{1}", Eval("ArgZero"), Eval("ArgOn"))%>'

Resources