Latest developer linksBookmark and Share
 
HomeThis WeekTop MonthTop AlltimeSearchRegisterFAQ
  
 
Submit Your Link
Please login to submit your Link
 

Dynamic Binding in a Static Language, Part 1

Posted: Dec/24/2009   By: pankaj   Points:15   Category: .NET  - ASP.Net    Views:165   Vote Up (0)   Vote Down (0)    
This article is taken from the book C# in Depth, Second Edition. This segment looks at what it means for code to be dynamic, and the syntax involved in using dynamic typing in C# 4

View Complete Post


Comments:
Be the first to comment this post.
 
Post Comment
Please login to post your comment
More Related Resources

What are C# Generics - Part II

  
Your main goal is to gain an appreciation of why we would want to use generics in the first place. The typical candidate scenario for the use of generics is where we have a class that has a member variable, and the type of this variable should be defined by the client of the class, and not by the programmer. Likewise, for a method that has a parameter passed to it. In other words, the code in our classes and methods remains the same and the types of the data can change with each use. Think code reuse.

Basic Ajax GridView in ASP.NET 2.0 - Part 2

  
Welcome to Basic Ajax GridView in ASP.NET 2.0 part 2, the second and final installation of this two part series regarding implementing basic Ajax features into an ASP.NET 2.0 application. During this second part of the series we will build upon the foundation we created during part 1 and add more Ajax enabled features to our sample application.

How to display dynamic XML data inside a Panel control?

  

Hi all,

I have a SQL routine which builds me an entire XML file and returns it as a string. 
If I save the content of this file as sample.xml for instance, I am able to open it in IE or any other browser and the user can expand the nodes and see all the content he wishes.

I am trying to build a ASP.Net page which will display the content of a XML file in the same way (or similar) that the browsers do.

So far, I've been reading some posts and noticed I can use XmlDataSource control and its Data property to load the entire XML doc as a string. Now I am stuck how to display the contents. I found TreeView very confusing and not sure if DataGrid would be a alternative as well. I need to user to be able to open and expand the nodes.

Please someone point me to the right direction. What controls to use, etc... sample codes are the best ;-)

Thank you

 


Need help: Issue with Dynamic Checkboxes CheckChanged Events

  

Hello All, I have almost broken my head on this whole day today, looks like i am not getting something and thats why its not working. Someone please help.

Below is the scenario:
In the aspx page, i am dynamically adding a checkbox to an htmltable.  To its CheckChanged event, i am adding one more row in the table and adding another checkbox. I am not able to get this new checkbox's CheckChanged event. I understand that its not getting created, but i am not sure how do i handle it.
Below is the code, can someone help me correct this code and help me on how do i achieve it.

Note: I have to use the HtmlTable.Rows.Insert method only, to add the new row with its controls to the HtmlTable based on indexes.

ASPX PAGE

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="WebApplication1.Default" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <div>        
        <table id="tblGenerator" runat="server"></table>
    </div>
    </form>
</body>
</html>
ASPX.CS PAGE - CODE BEHIND

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;

namespace WebApplication1
{
    public partial class Default : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            tblGenerator.Style.Add("border", "1");
            tblGenerator.EnableViewState = true;
            HtmlTableRow tblRow = new HtmlTableRow();

            HtmlTableCell tblCellLeft = new HtmlTableCell();
            HtmlTableCell tblCellRight = new HtmlTableCell();

            Label lblOne = new Label();
            lblOne.ID = "lblOne_1";
            lblOne.Text = "This is for checkbox 1";
            tblCellLeft.Controls.Add(lblOne);

            CheckBox chkBoxOne = new CheckBox();
            chkBoxOne.ID = "chkOne_1";
            chkBoxOne.AutoPostBack = true;
            chkBoxOne.EnableViewState = true;
            chkBoxOne.CheckedChanged +=new EventHandler(chkBoxOne_CheckedChanged);
            tblCellRight.Controls.Add(chkBoxOne);

            tblRow.Cells.Add(tblCellLeft);
            tblRow.Cells.Add(tblCellRight);

            tblGenerator.Rows.Add(tblRow);            
        }

        void  chkBoxOne_CheckedChanged(object sender, EventArgs e)
        {
            CheckBox chkBox = (CheckBox)sender;

            HtmlTableRow parentRow = (HtmlTableRow)chkBox.Parent.Parent;
            HtmlTable parentTable = (HtmlTable)chkBox.Parent.Parent.Parent;

            int index = parentTable.Controls.IndexOf(parentRow);

            HtmlTableRow newRow = new HtmlTableRow();
            HtmlTableCell childTblCellLeft = new HtmlTableCell();
            HtmlTableCell childTblCellRight = new HtmlTableCell();

            Label childLblOne = new Label();
            childLblOne.ID = "childLblOne_1";
            childLblOne.Text = "This is for child checkbox";
            childTblCellLeft.Controls.Add(childLblOne);

            CheckBox childChkBoxOne = new CheckBox();
            childChkBoxOne.ID = "childChkOne_1";
            childChkBoxOne.AutoPostBack = true;
            childChkBoxOne.EnableViewState = true;
            childChkBoxOne.CheckedChanged += new EventHandler(childChkBoxOne_CheckedChanged);
            childTblCellRight.Controls.Add(childChkBoxOne);

            newRow.Cells.Add(childTblCellLeft);
            newRow.Cells.Add(childTblCellRight);

            //add 1 to the parent table's row index to insert new row to the parent table ...            
            parentTable.Rows.Insert(index + 1, newRow);            
        }

        void childChkBoxOne_CheckedChanged(object sender, EventArgs e)
        {
            Response.Write("Child checkbox changed");
        }
    }
}



 


Dynamic gridview paging

  

Hi, all --

I've already searched to no avail for an answer to this question: is it possible to dynamically alter the page size in a paged gridview based on data in a particular column? In other words, let's say I get data from a table that lists students enrolled in a particular course. If there are 10 students in Course "A," then I want page 1 in my gridview to show 10 records. If there are 15 students in Course "B," then I want page 2 in my gridview to show those 15 records, and so on. I imagine that this could probably be done with a master-detail kind of set up, but let's say for the sake of argument that I don't want to go that route.

Thanks in advance for any suggestions.

Ken



Using VB, how do I use the For i = 1 to 10 to create a dynamic double variable

  

I have some global variables declared and want to access them in subrorutines using the For statement. 

For example, I want to use the following to place values in the global variables , i.e, dblcell1, dblcell2, dblcell3, etc. 

Dim m As Integer
			For m = 3 To 11
				If e.Row.Cells(m).Text <> " " Then
					dblCell & m = e.row.cells(m).text)
				End If
			Next

I know that I can't use the "dblCell & M".  It is just to show the objective. It is where I get an error.

 

Thanks
 

 


Possible routing or model binding bug in mvc 3 rc 2

  

Hi,

Have been able to get a really strange behavior in mvc 3 rc 2, where an controller action (a) in an area has a nullable enum and long as parameter and an controller action (b) (which is not placed in an area) only have nullable long.

If I compile and first surf to (a) then it works, and then surf to (b) with a number as parameter it throws exception where it seem to have tried to pass the nullable enum!

If I recompile and surf to (b) with same parameter it works, and if I surf to (a) the enum is always null.

Edit: perhaps this is a model binding bug, perhaps caused by some internal cache? Since the routes are correct but the passed arguments are not.

I have setup a dummy mvc 3 rc2 project, tell me where I can post/mail it for better explanation if needed.

Regards,
Daniel


captcha image isnt't being generated in production part...

  

guys,

I used a custom captha inside my mvc application and it works perfectly fine in local but in production it isn't being generated. why is that?

I used the following statement for saving the image. do you think it is beacuse of that?

                        using (var memoryStream = new MemoryStream())
                        {
                            bmp.Save(memoryStream, ImageFormat.Png);
                            memoryStream.WriteTo(Response.OutputStream);
                        }




Dynamic Data URLs

  

Ok, so I have a fully functioning DynamicData website, and all works fine when debugging in VS2010

 

But when I moved the site to a webserver (server 2008, IIS7)  the default paeg comes up, but any links or pages after that are all sending 404 errors

 http://{IP address}/{table}/{action}.aspx

does not work when on the server, but works fine in VS.

 

What configuration am i missing from IIS7 to make this url work?


Does Dynamic Data support soft delete feature?

  

Due to auditing purpose, we are not supposed to delete records from the database. Instead we update a flaf which will mark it as deleted. Is there a way to accomplish this is Dynamic Data?

 At current I am overriding the partial method in datacontext and executing my own query. I wanted to check if other members in the community have a different approach.


 
Categories:
.NET
Java
PHP
C/C++/VC++
HTML/XML
SAP
MainFrames
Data Warehousing
Testing
MySQL
SQL Server
Oracle
Javascript/VB Script
Others
Login
 
 
 
 
 Forgot password
 Contact Us   Terms Of use   Share your knowledge