Archive

Archive for November, 2013

Change Export File Name in Report Viewer

November 26, 2013 Leave a comment

Hi all,

try this example to Change Exported File Name in Report Viewer

Add this code in Page Load


string filename = Guid.NewGuid().ToString();
ReportViewer1.LocalReport.DisplayName = filename;

Hope this helps

Good Luck.

Advertisements
Categories: ASP.Net

JQuery to Bind DropDownList from Database

November 25, 2013 Leave a comment

Hi all,

try this example to use JQuery to Bind DropDownList from Database

In this example i will bind Dropdownlist to Categories table in Northwind database.

1) Open VS 2008 and create a new website and add new Page

2) From Toolbox drag and drop dropdownlist control into your page


<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_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>
 <script src="jquery-1.8.3.js" type="text/javascript"></script>
 <script type="text/javascript">
 $(document).ready(function() {
 $.ajax({
 type: "POST",
 contentType: "application/json; charset=utf-8",
 data: "{}",
 url: "Default.aspx/GetData",
 dataType: "json",
 success: ajaxSucceess,
 error: ajaxError
 });
 function ajaxSucceess(response) {
 $("#<%=ddl_Category.ClientID%>").empty();
 $("#<%=ddl_Category.ClientID%>").append($("<option></option>").val('-1').html('Please Select'));
 $.each(response.d, function(key, value) {
 $("#<%=ddl_Category.ClientID%>").append($("<option></option>").val(value.CategoryId).html(value.CategoryName));
 });
 }
 function ajaxError(response) {
 alert(response.status + ' ' + response.statusText);
 }
 });
</script>
</head>
<body>
 <form id="form1" runat="server">
 <div>
 Select Category :
 <asp:DropDownList ID="ddl_Category" runat="server" AppendDataBoundItems="True">
 <asp:ListItem Text="Please Select" Value="-1"></asp:ListItem>
 </asp:DropDownList>
 </div>
 </form>
</body>
</html>

3) In 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.Services;
using System.Data;
using System.Configuration;
using System.Data.SqlClient;

public partial class _Default : System.Web.UI.Page
{
 protected void Page_Load(object sender, EventArgs e)
 {

}
 [WebMethod]
 public static List<Category> GetData()
 {
 List<Category> CategoryCollection = new List<Category>();
 try
 {
 DataSet Ds = GetDataSet("Select * from Categories");
 CategoryCollection = Ds.Tables[0].AsEnumerable().Select(data => new Category() { CategoryId = (int)data["CategoryId"], CategoryName = (string)data["CategoryName"] }).ToList();
 }
 catch (Exception) { }
 return CategoryCollection;
 }
 public static DataSet GetDataSet(string Query)
 {
 DataSet Ds = new DataSet();
 try
 {
 string strCon = ConfigurationManager.ConnectionStrings["conn"].ConnectionString;
 SqlConnection Con = new SqlConnection(strCon);
 SqlDataAdapter Da = new SqlDataAdapter(Query, Con);
 Da.Fill(Ds);
 }
 catch (Exception) { }
 return Ds;
 }
}

public class Category
{
 public int CategoryId { get; set; }
 public string CategoryName { get; set; }
}

Hope this helps

Good Luck.

Categories: ASP.Net, Jquery

Open JQuery Dialog Modal on F9 Key Press

November 15, 2013 Leave a comment

Hi all,

try this example to open jquery dialog modal on F9 key press


<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default3.aspx.cs" Inherits="_Default" %>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
 <title></title>
 <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
 <script src="http://ajax.aspnetcdn.com/ajax/jquery.ui/1.8.9/jquery-ui.js" type="text/javascript"></script>
 <link href="http://ajax.aspnetcdn.com/ajax/jquery.ui/1.8.9/themes/start/jquery-ui.css" rel="stylesheet" type="text/css" />
 <script type="text/javascript">
 $(function() {
 $(document).keyup(function(e) {
 var key = (e.keyCode ? e.keyCode : e.charCode);
 switch (key) {
 case 120: // f9 key
 $(".dialog").dialog({
 title: "jQuery Dialog Title",
 buttons: [{
 text: "اغلاق",
 click: function() {
 $(this).dialog("close");
 }
 }],
 modal: true,
 width: 300,
 hieght: 100,
 resizable: false,
 closeOnEscape: true
 });
 break;
 default: ;
 }
 });
 });
</script>
</head>
<body>
 <form id="form1" runat="server">
 <div id="dialog" class="dialog" style="display:none">
 This is JQuery Dialog
 </div>
 </form>
</body>
</html>

Hope this helps

Good Luck.

Categories: ASP.Net, Javascript, Jquery

Allow Number Only in TextBox

November 13, 2013 1 comment

Hi all,

try this example to allow user to type number only without decimal in ASP.Net TextBox Control


<script type="text/javascript">
 function CheckNumberOnly(e) {
 var unicode = e.keyCode ? e.keyCode : e.charCode;
 var characters = '0123456789';
 var keychar = String.fromCharCode(unicode);
 if (characters.indexOf(keychar) != -1) {
 return true;
 }
 else {
 return false;
 }
 }
 </script>

and in code behind :

TextBox1.Attributes.Add("onkeypress", "return CheckNumberOnly(event)");

For more information you can check my previous posts

Make TextBox accept Number only

Allow Number Only In ASP.Net TextBox

Hope this helps

Good Luck.

Categories: ASP.Net, Javascript Tags: