473,786 Members | 2,775 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Calling function using repeater (vb vs. c#)

Hello,

I am calling a function using vb and want to convert it to c#. When moving
from vb 1.1 to vb 2.0, I can use the following: text='<%#
AddBlankRowMenu (Eval("strMenuT ype")) %>' to call the function. I no longer
need to use "DataBinder.Eva l(Container,"Da taItem." in front of the DataItem.
However, when I tried to use the new syntax in c#, I got an error. However,
the older syntax works.

Am I missing something, or does c# require the longer syntax as shown below?

--
Thanks, sck10


vb: asp.net 1.1
<asp:Literal id="ltrNewLine " text='<%#
AddBlankRowMenu (DataBinder.Eva l(Container,"Da taItem.strMenuT ype")) %>'
runat="server" />

vb: asp.net 2.0
<asp:Literal id="ltrNewLine " text='<%# AddBlankRowMenu (Eval("strMenuT ype"))
%>' runat="server" />
c#: asp.net 2.0
<asp:Literal id="ltrNewLine " text='<%#
AddBlankRowMenu (DataBinder.Eva l(Container,"Da taItem.strMenuT ype")) %>'
runat="server" />
Jul 28 '06 #1
1 3504
Hello Steve,

As for the databinding expression in ASPX template, they're dynamically
compiled at runtime, and the error you encountered is likely due to the
different compile option between VB.NET and C#. For VB.NET, it is using
latebinding that means wo do not need to convert the object to the actual
expected type and the runtime will use latebinding to evaluate and
determine the object type. However, C# will always enforce type checking
at compile time, if there is type mismatch in code, it will report error.

Thus, for your case, "DataBinder.Eva l" or "Eval"(asp. net 2.0 specific)
will return an "Object" , however, our custom function( such as the
"AddBlankRowMen u" ) will expect a non-Object type parameter, this will
cause the C# compilter report error. What's the object type expected by
the "AddBlankRowMen u" function in your case? You can consider:

1. Explicitly case the object returned from the "Eval" to the expected
type of the "AddBlankRowMen u" function before pass it to the function.

2. Change the "AddBlankRowMen u"'s input parameter to "Object" type , and
perform the type convertion inside the function.

Please feel free to let me know if there works for you or if you meet any
further problem on this.

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead

=============== =============== =============== =====

Get notification to my posts through email? Please refer to

http://msdn.microsoft.com/subscripti...ult.aspx#notif
ications.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial

response from the community or a Microsoft Support Engineer within 1
business day is

acceptable. Please note that each follow up response may take approximately
2 business days

as the support professional working with you may need further investigation
to reach the

most efficient resolution. The offering is not appropriate for situations
that require

urgent, real-time or phone-based interactions or complex project analysis
and dump analysis

issues. Issues of this nature are best handled working with a dedicated
Microsoft Support

Engineer by contacting Microsoft Customer Support Services (CSS) at

http://msdn.microsoft.com/subscripti...t/default.aspx.

=============== =============== =============== =====

This posting is provided "AS IS" with no warranties, and confers no rights.
Jul 31 '06 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
1684
by: Andrew Banks | last post by:
I've got the following code as part of a C# web form but am having problems calling a command. I create a dataset and put some data on the screen. This works fine. (relevant sample below) foreach (DataRow row in ds.Tables.Rows) { detailsbtn = new LinkButton(); //Assign a unique ID to the details control detailsbtn.ID = "details" + row.ToString().Replace("-", String.Empty);
0
1542
by: Kent P. Iler | last post by:
Hi, I have a data repeater that is returning a list of events. One of the things I want to do is give the user a way to edit or delete an event. My plan was to use an Imagebutton that would invoke a codebehind function that would either edit or delete the item. My problem is I need to pass the event_id as a parameter to each of these functions so I know what event to edit/delete. The error code is complaining about the way I'm trying...
4
3395
by: Ryan Ternier | last post by:
I have a button event: Public Sub SwitchItem(ByVal sender As System.Object, ByVal e As System.EventArgs) Dim btnTest As New Button Dim astrTest As String() btnTest = CType(sender, Button) astrTest = btnTest.ClientID.Split("_") strControlsToEdit = astrTest(2)
5
4304
by: qwerty | last post by:
I have tried to call the Repeater´s item´s DataItem example from Page´s functions. I have put to the Repeater ID and Name got from the database. I have tried following: CType(Repeater(index).DataItem, DataRowView)("ID") DataBinder.Eval(Repeater(index).DataItem, "ID") First get me "NullReferenceException" and second zero length string.
0
1194
by: tenaka2k | last post by:
OK I have poked around and have not found an answer to my problem . I have a repeater that in it's <ItemTemplate> calls a function I want to pass the current values from the repeater to the function. I have yet to Figgure out how to get the Evals Data to goto the function as the current code does not work. Producing an error of : "System.InvalidOperationException: Databinding methods such as Eval(), XPath(), and Bind() can only be used...
3
9170
by: Brian | last post by:
Using external XML, I'm trying to build a quiz, but I can't seem to specify the DataSource for the RadioButtonList within a Repeater ItemTemplate. I've tried a number of approaches, but I haven't really had any success. I'm pretty sure I should be casting my XPathSelect() call to something so I can get at its attributes. This seems like it should be easy, and maybe I'm missing something obvious. Does anyone have any ideas? Here is the...
4
3480
by: sck10 | last post by:
Hello, I am trying to call a function (c#) from the repeater tool and I am not sure if I am calling the function correctly (since I am not getting the results that I want). Using <asp:Literal id="ltrNewLine" text='<%# vbBlankRowMenu("strMenuType") %>' runat="server" />
1
7133
by: jazzart | last post by:
Hi there, I'm fairly new to programming with Asp.Net 2.0 so I'm finding myself regularly fumbling around in the dark a bit, so to speak. I'm currently using Visual Web Developer and have been following the www.asp.net data access tutorials to create a DAL and BLL to connect my web site (a simple real estate property search web site) to my database (Sql Express 2005).
0
774
by: orangelightbulb | last post by:
Hi I have a repeater and want to add a function to a field the function is this public static void CreateSendertMessage(string server) { string s_html; s_html = server.ToString();
0
9650
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9497
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10363
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10110
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9962
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
6748
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5398
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
2
3670
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2894
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.