.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month
Gaurav Pal
Post New Web Links

DataBinding + Extension Method Problem

Posted By:      Posted Date: October 24, 2010    Points: 0   Category :ASP.Net

Inside my repeater I'm calling an extension method like so:


<asp:label id="fileSize" runat="server" text='<%# ((UploadedFile)DataBinder.GetDataItem(Container.DataItem)).Size() %>' />


he above is giving me an "Object not set to an instance of a object" exception inside the extension method. If I comment the above expression out, it works fine, and the items are binded wtih no problems. Any ideas?

View Complete Post

More Related Resource Links

Problem with Finder method with parameters



Could someone explain me how to provide some value to the parameters in a finder method. For exemple I know that the BDC list WP use this method. Is there a way to provide some value for those parameter at runtime? I really don't understand (even after some deep search on the web) where are the values for the parameters from and how we can connect to them. Even with C# code I can't find any information on how it work.

I don't want to define my parameters as filter in the ADF because then I will have this filter section in my BDC list WP (or is there a way to get rid of that?). Actually one of the parameter should be automatically calculated from a value in a SP list, the other parameter should be provided by my own filter web part.

Thank you for your help.

Accordian DataBinding problem

Hi Folks, I am having a strange problem with an Accordian control which is databound to a DataView. Each pane displays data about a person. The problem is that when a new person is added which sorts to one of the inner panes, it initially displays the content (but not the header) of the pane following. For example, if there are two panes, one for Andy and one for Mary, and I add a new person named Bill, then the headers will be Andy, Bill and Mary, as expected. But expanding Bill will show the info for Mary. Both Andy and Mary display the correct data.  If I leave the page and return, all displays correctly. I have stepped through the code, listed below,  and verified to my satisfaction that when I rebind the control, the data in the underlying datatable and dataview is correct. Any thoughts? Thanks. Dan   Here is the declaration of the Accordian control:  <cc1:Accordion ID="accPeople" runat="server"   Width="400px" Height="100" TransitionDuration="1" AutoSize="None"   RequireOpenedPane="false"  SelectedIndex="-1" ContentCssClass="AccCntnt" HeaderCssClass="AccHdr"   HeaderSelectedCssClass="AccHdrSlctd">  <HeaderTemplate>    <table >      <tr>  

Extension Method ForEach for ArrayList class

Hi,I need to create an extension method(ForEach) for arraylist classI have created an extension method for Array class but cannot do that for arraylist.Please help me namespace MyExtension { public static class IEnumerableExtension { public static void ForEach<T>(this IEnumerable<T> list, Action<T> action) { if (action == null) throw new ArgumentNullException("action"); foreach (T item in list) { action(item); } } } } Any Help Shall be appreciatedThanks

Problem with overriding OnPaint method of System.Windows.Forms.Textbox

Hi,   I want to change the border colour of the Textbox. However, when I override the OnPaint method, some strange behaviour occurs.   The new border is drawn, as is the textbox background. However, the text itself appears in bold and only while I actually type something in, afterwards it disappears. I have provided a sample of my code here:         protected override void OnPaint(PaintEventArgs e)         {             base.OnPaint(e);             Rectangle rect = new Rectangle(0, 0, this.Width, this.Height);             ControlPaint.DrawBorder(e.Graphics, rect, _BorderColour, ButtonBorderStyle.Solid);         }   I have also set the style of the control to Userpaint, so that the paint method is actually used. Does anybody know how to solve this issue?

WPF databinding problem with templates, kind of comlpex. Can someone help me?

Hey there, I have to following problem: In my MainWindow.xaml I declared a control like this: <Control Name="lvLeidingen" Template ={StaticResourceResourceKey =ListView}"></Control>   This creates a control which references to a resource ControlTemplate where a ListView is defined. which is done like this:   <ControlTemplate x:Key="ListView"> <ListView> <ListView.View> <GridView ColumnHeaderContainerStyle="{DynamicResource ResourceKey=ListViewColumn}"> <GridViewColumn CellTemplate="{DynamicResource ResourceKey=DiameterCell}"> </GridViewColumn> <GridViewColumn CellTemplate="{DynamicResource ResourceKey=WanddikteCell}"> </GridViewColumn> <GridViewColumn CellTemplate="{DynamicResource ResourceKey=BuisMateriaalCell}"> </GridViewColumn> </GridView> </ListView.View> <ListView.Items> <ListViewItem> </ListViewItem> </ListView.Items> </ListView> </ControlTemplate> And here are the DataTemplates for the celltemplates:   <DataTemplate x:Key="DiameterCell"> <ComboBox ItemsSource="{Binding Path=Diameters}"> </ComboBox> </DataTemplate>   The other templates for WanddikteCell and BuisMateriaalCell are done the same way..  

Problem using value() method for xml datatypes.

Hi i'm working on an application which stored infopath forms in database as xml datatype. now i want to get query of xml data which returns each node as sql dataType (column). here is my sample form data : <?mso-infoPathSolution solutionVersion="" productVersion="12.0.0" PIVersion="" href="file:///D:\customForm3.xsn" name="urn:schemas-microsoft-com:office:infopath:customForm3:-myXSD-2010-09-11T10-56-47" ?> <?mso-application progid="InfoPath.Document" versionProgid="InfoPath.Document.2"?> <my:myFields xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xhtml="http://www.w3.org/1999/xhtml" xmlns:my="http://schemas.microsoft.com/office/infopath/2003/myXSD/2010-09-11T10:56:47" xmlns:xd="http://schemas.microsoft.com/office/infopath/2003" xml:lang="en-us"> <my:txtFirstName>test1</my:txtFirstName> <my:txtLastName>test2</my:txtLastName> <my:txtFatherName>test3</my:txtFatherName> <my:txtNationalCode>8278273828</my:txtNationalCode> <my:cmbReuqesType>2</my:cmbReuqesType> <my:dtmRequestDate>2010-09-17</my:dtmRequestDate> <my:txtDescription>test4</my:txtDescription> </my:myFields> to get query of this

Problem canceling asynchronous method



I want to canceling an asynchronous method.

How can me it?


public IAsyncResult BeginGetAllUsersCount(object sender, EventArgs args, AsyncCallback callback, object state)
       //Canceling asynchronous operation
     return AdapterUser.BeginGetAllUsersCount(callback);

   public void EndGetAllUsersCount(IAsyncResult asyncResult)
     _totalRowsCount = AdapterUser.EndGetAllUsersCount(asyncResult);




Problem while calling WCF method


I have a WCF Service and a client application. WCF Service has an operation contract (say UpdateTables()) with IsOneWay = True. I call this method of WCF Service from my client application using the code below:
   Private Sub UpdateTable_Client()
        Dim WCFSvcObject As New MyFirstWCFServiceClient
        Dim WCFSvcData as new MyFirstWCFDataRequest 'DataContract object
        WCFSvcData.TableName = "Customer"
        WCFSvcData.ColumnName = "Name"
        Catch ex As Exception
            Throw ex
            If WCFSvcObject  IsNot Nothing Then               
            End If
        End Try
    End Sub

Sometimes this call reaches to WCF Service successfully but sometime it lost and UpdateTable() method could not be invoked on service side. I am not sure but I think WCFSvcObject.Abort() code aborts the WCF request before it reaches to the service. I can not use Close() method here as my client application hangs on the Close().
Please suggest me what may be the reasons of the client call could not reach to the WCF Service. Should I not use Abort() method. If yes then how can I dispose the WCF proxy(since Close() method is not working here).

Problem creating method?


I added the extender and when i tried to add the method this message poped up;

Cannot create page method "GetCompletionList" because no Code Behind or codefile was found.

does anyone know why this is happening?

Thanks  =)

Unusual problem using a class method


I have a class that runs calculations on numbers and populates the results to my SQL database.  My code behind page instantiates the class object, and in a loop it makes use of the method five times (once per loop).  Essentially, my code behind collects the information from controls and passes the information to the class method for processing.  The method works just fine most of the time.

On one of the iterations I get a error before the code even gets to the class.  The error is, "Arithmetic operation resulted in an overflow."  What strikes me as odd is that while stepping through the code, the loop crashes with that error before getting to the class that runs the calculations.  Additionally, no arethmetic operations are performed on the form's code-behind page (which calls the method).  I even put a break-point on the class constructor but the code crashed before reaching that constructor.

The information being sent is the results of matches from a sporting event.  As a troubleshooting measure I changed the order of the matches by deleting them an re-entering them into the database in a different order.  Again only this one particular match crashed.

Here is the code that crashes:

cRating.SetRating(dMatchDate, iSetID, 8, iHPlayerID, 

Gridview Dropdownlist databinding problem


I am using gridview, in ItemTemplate  I am using dropdownlist which has the hard-coded value, I want to get updated value of dropdownlist from database, but whenever I use EVAL, it throws the following error:

 'ddl' has a SelectedValue which is invalid because it does not exist in the list of items.

Parameter name: value

I am using the following code:

<asp:TemplateField HeaderText="Status"  >
                      <asp:DropDownList ID="ddl" runat="server" SelectedValue='<%# Bind("Status")%>' >

problem with my method


this method is meant to retrieve two database field values, but i'm getting error: Must declare the scalar variable "@FlyingFrom".

 public static string GetDepartureFlightId()

            //sql query
            string sqlQuery = @"SELECT DepartureId
                                FROM Flights WHERE FlyingFrom = @FlyingFrom"; 

            using (SqlConnection myConnection = new SqlConnection(ConfigurationManager.ConnectionStrings["MyConnectionString"].ConnectionString))
                string depId = "";
                string flyingFrom = "";
                SqlCommand myCommand = new SqlCommand(sqlQuery, myConnection);

                SqlDataReader reader = myCommand.ExecuteReader(CommandBehavior.CloseConnection);

                while (reader.Read())
                    depId = reader["DeparturedId"].ToString();
                    flyingFrom = reader["FlyingFrom"].ToString();


                return sqlQuery;


Problem in inserting another entity via overriding insert method


I have problem to inserting another entity in overriding method of first entity my code sample is like bellow :

partial void InsertEntity1 ( Entity1 instance )


     Entity2 x = new Entity2() ;

tihs.Entity2s.Add(x) ;





in inserting Entity2 I get Exception "The Operation Cannot be perform for the entity because it is not being change track"


problem on indexOf() method



Whats wrong in this code? I can not use indexOf method.

        function CancelPostback() {
            var TextBoxDescription
            TextBoxDescription = document.getElementById('<%=(((Master.FindControl("MainContent")).FindControl("FormViewPO")).FindControl("DescriptionTextBox")).ClientID %>');
            alert(TextBoxDescription.value)  // working. Alert shows value of the textbox
            //  alert(TextBoxDescription.value.indexOf("a")) // not working. even no alert
            //  alert(TextBoxDescription.indexOf("a")) // not working. even no alert
            //  alert(TextBoxDescription.value.indexOf('a')) // not working. even no alert
            //  alert(TextBoxDescription.indexOf('a')) // not working. even no alert

file extension problem


I try to upload  .mdb file to wss 3.0 and get an error message. When I go to Central  Administration - Operations - Blocked files type, I can delete the extension from the list, but I cannot click ok - the change doesn't stay.  Please, help



interesting problem about @ and extension methods.


Note , that i'm new to c# so it might not be a problem.

first , what is the exact meaning of @ in Razor ?

does it mean WebPage.Response.Write ?

next, i designed an extension method to WebPage ( by the way that is the coolest feature ever in c# )

in my Razor code , to use it in a webpage , i must write @this.MyExtensionMethod() instead of @MyExtensionMethod().

So why is it?  because @this.MyExtensionMethod() and @MyExtensionMethod() should be the same ?

here is my extension method :

using System;
using System.Web;
using System.Web.WebPages;

namespace MyExtenstionMethods{

	public static class Utility{

	    // make the page to render optional
		public static dynamic RenderOptionalPage(this WebPage Webpage ,string page="",params object[] data){

				return Webpage.RenderPage(page,data);
            }catch(HttpException ex){
                return new HtmlString("<!-- page not found -->");


Problem with the XMLNodeList.SelectSingleNode method



I was doing an experiment with the XML. Bellow given is XML file


I have written the following piece of code to get the NodeList

private ConfigData ReadConfig()
            XmlDocument powerDoc = new XmlDocument();
            ConfigData config = null;
            XmlNode node = null;
            XmlNodeList emailList = null;

ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  Silverlight  Others  All   

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend