google

Newest Post

Showing posts with label AJAX. Show all posts
Showing posts with label AJAX. Show all posts

Code to export the Grid View/Data Grid data into Excel File.

| Friday, February 13, 2015
Read more »
 protected void btnExportToExcel_Click(object sender, EventArgs e)  
   {  
     try  
     {  
       DataTable dt = student.GetDetails("B.Tech").Tables[0];  
       DataGrid GridView1 = new DataGrid();  
       GridView1.DataSource = dt;  
       GridView1.DataBind();  
       Response.Clear();  
       Response.Buffer = true;  
       Response.AddHeader("content-disposition", string.Format("attachment; filename=StudentsBTech.xls"));  
       Response.Charset = "";  
       Response.ContentType = "application/vnd.ms-excel";  
       StringWriter sw = new StringWriter();  
       HtmlTextWriter htw = new HtmlTextWriter(sw);  
       GridView1.GridLines = GridLines.Both;  
       GridView1.AllowPaging = false;  
       GridView1.RenderControl(htw);  
       Response.Output.Write(sw.ToString());  
       GridView1.DataBind();  
       Response.Flush();  
     }  
     catch (Exception ex)  
     {  
     }  
     finally { Response.End(); }  
   }  
   public override void VerifyRenderingInServerForm(Control control)  
   { }  

Code to export the Grid View/Data Grid data into Excel File.

Posted by : Stranger
Date :Friday, February 13, 2015
With 0comments

Could not add reference to "System.Net.Http.Formatting" namespace in WPF web api client project

| Friday, December 12, 2014
Read more »
For adding the reference in your web api client

1. Right click on "References" in the solution.
2. Following window will open.


3. Select location "Extension" as shown above and check "System.Net.Http.Formatting" namespace
4. and DONE!!!

Update the .edmx file when the database changes

| Saturday, May 17, 2014
Read more »
To update the .edmx file when the database changes

  1. In the Model Browser, right-click the .edmx file and select Update Model from Database.
  2. The Update Model Wizard starts. If there is no database connection specified, the Choose Your Database Connection dialog box appears. Otherwise, the Choose Your Database Objects dialog box appears. 
  3. If the Choose Your Database Connection dialog box appears, specify a database connection. Otherwise, go to the next step.
  4. For details about specifying a connection, see Choose Your Data Connection Dialog Box (Entity Data Model Wizard). When you have specified the connection, click Next to display the Choose Your Database Objects dialog box.
  5. Click the Add tab.
    Nodes for tables, views, and stored procedures are displayed. If any objects have been added to the database (or were not included in the previous storage model), you can expand the corresponding node to view the objects that are available to add to the conceptual model.
  6.  If an object has been deleted from the conceptual model but has not also been deleted from the storage model, the object will not be available to add to the conceptual model.
  7. Expand the Tables, Views, and Stored Procedures nodes, and check the objects you want to add to the .edmx file.
  8. Click the Refresh tab.
    Nodes for tables, views, and stored procedures that are included in the existing storage model are displayed. Any changes that have been made to these database objects will be reflected in the updated storage model. Changes to the conceptual model are made when columns are added to a table or view.
  9. Click the Delete tab.
    Nodes for tables, views, and stored procedures are displayed. If an object has been deleted from the database and was included in the previous storage model, you can expand the corresponding node. The objects in these nodes will be deleted from the updated model.
    Click Finish to update the .edmx file with the database changes.

Reference - MSDN

Update the .edmx file when the database changes

Posted by : Stranger
Date :Saturday, May 17, 2014
With 0comments

Unable to find the requested .Net Framework Data Provider. It may not be installed.

| Thursday, April 10, 2014
Read more »
Above error can be caused by if the "Provider" given in "SqlDataSource" or any other data source control is not updated.

This error can be resolved either by updating the Provider details in connection string property of web.config file or you simply remove the

 ProviderName="<%$ ConnectionStrings:DbConnectionString.ProviderName %>"  


from SqlDataSource control or any other data source control.

ScriptManager.RegisterStartupScript using JavaScriptSerializer - To display the Alert or Message Box from Code behind

| Thursday, March 13, 2014
Read more »
While registering a message using the javascript code in RegisterStartupScript, message might contain some escape characters like ' or " this will definitely break the javascript. Hence we need to encode it, for example using JavaScriptSerializer as follows.



  string message = new JavaScriptSerializer().Serialize(ex.Message.ToString());  
  string myScript = String.Format("alert('{0}');", msg);  
  ScriptManager.RegisterStartupScript(page, page.GetType(), "MyScript", myScript, true);  




How to - Populate RadEditor's Apply CSS Class dropdown with custom styles.

| Tuesday, January 28, 2014
Read more »
Populate RadEditor's Apply CSS Class dropdown with custom styles.


 <telerik:RadEditor runat="server" ID="RadEditor1" SkinID="DefaultSetOfTools" Height="400px"  
 Width="100%" >  
 <CssFiles>  
    <telerik:EditorCssFile Value="mystyle.css" />  
 </CssFiles>   
 </telerik:RadEditor>  

How to - Populate RadEditor's Apply CSS Class dropdown with custom styles.

Posted by : Stranger
Date :Tuesday, January 28, 2014
With 0comments

Ajax Rating Control for ASP.Net to get the Star rating of hotel, save it into the database and get its value from database.

| Thursday, January 24, 2013
Read more »

Download the detailed code here

The Rating control allows users to select the number of stars that represents their rating.

The page designer can specify the initial rating, the maximum rating to allow, the alignment and direction of the stars, and custom styles for the different states a star can have.

In the current example, we will use rating control in the form of stars and will be used to choose the star rating of a hotel. The rating chosen will be saved in the database and displayed from the database on page load.

Following are the properties of Rating Control:  

OnChanged – This event is used to get how many stars user has selected.

AutoPostBack – This property should be true to store rating during rating item click.

CurrentRating – This property is used to display Initial rating value (Number of stars to be filled initially).

MaxRating – This property is used to display maximum rating value (No. of stars here I am displaying only 5 if you want to increase stars value give property like this MaxRating=10).

StarCssClass – This cssclass is used for to display stars.

WaitingStarCssClass – This cssclass is used to show the starts color during saving the rating value.

EmptyStarCssClass – This cssclass is used to display empty stars color.

FilledStarCssClass – This cssclass is used to display filled stars color.

ReadOnly – This property is used to make rating control read only.

RatingAlign – This property is used to set stars vertical or horizontal.

RatingDirection – This property is used to set the direction of stars(LeftToRight or TopToBottom or RightToLeft or BottomToTop).

To save the rating details into the database, create the table with following columns:
  1. Id (int)
  2. HotelName (varchar(200)
  3. StarRating (int)
Add the reference of "AjaxControlToolKit.dll" into your website project and connection string to attach the website with database in the web.config.

Following 3 images are being used to show case the different states of the star rating.
Saved




Empty



       
Filled




Add the rating control on the page designer and set its following properties

AutoPostBack="true" OnChanged="RatingControlChanged" StarCssClass="ratingEmptyCss" WaitingStarCssClass="ratingSavedCss" EmptyStarCssClass="ratingEmptyCss" FilledStarCssClass="ratingFilledCss"

The CSS classes being used can be declared in a separate css file or in the can be added inline."OnChanged" event is fired when rating item is clicked in the browser. This event is being used to save the star rating in the database.

NOTE : In certain scenarios, postback on rating item click is not required. To do that add following line of code in the code behind file(.cs file)

Rating1.Attributes.Add("onclick", "return false;")

Or add as an attribute to the rating control in the page designer as follows:

onclick="return false;"


The page in browser will look like this

Prev
▲Top▲