Friday 21 June 2013

Enable Disable Checkbox in Asp.net Gridview ( C#)

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Enable/Disable Checkbox in Gridview based on condtion in Asp.net</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:GridView ID="gvDetails" AutoGenerateColumns="false" CellPadding="5" runat="server" OnRowDataBound="gvDetails_RowDataBound">
<Columns>
<asp:TemplateField>
<ItemTemplate>
<asp:CheckBox ID="chkSelect" runat="server" />
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField HeaderText="UserId" DataField="UserId" />
<asp:BoundField HeaderText="UserName" DataField="UserName" />
<asp:BoundField HeaderText="Education" DataField="Education" />
<asp:BoundField HeaderText="Location" DataField="Location" />
</Columns>
<HeaderStyle BackColor="#df5015" Font-Bold="true" ForeColor="White" />
</asp:GridView>
</div>
</form>
</body>
</html>

C#
--------
using System;
using System.Data;
using System.Data.SqlClient;
using System.Web.UI.WebControls;

protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
BindGridviewData();
}
}
protected void BindGridviewData()
{
DataTable dt = new DataTable();
dt.Columns.Add("UserId", typeof(Int32));
dt.Columns.Add("UserName", typeof(string));
dt.Columns.Add("Education", typeof(string));
dt.Columns.Add("Location", typeof(string));
DataRow dtrow = dt.NewRow();    // Create New Row
dtrow["UserId"] = 1;            //Bind Data to Columns
dtrow["UserName"] = "Sujoy Santra";
dtrow["Education"] = "MCA";
dtrow["Location"] = "KOLKATA";
dt.Rows.Add(dtrow);
dtrow = dt.NewRow();               // Create New Row
dtrow["UserId"] = 2;               //Bind Data to Columns
dtrow["UserName"] = "Soumi Das";
dtrow["Education"] = "BA";
dtrow["Location"] = "KOLKATA";
dt.Rows.Add(dtrow);
dtrow = dt.NewRow();              // Create New Row
dtrow["UserId"] = 3;              //Bind Data to Columns
dtrow["UserName"] = "Sayani Santra";
dtrow["Education"] = "KG1";
dtrow["Location"] = "BAKHRAHAT";
dt.Rows.Add(dtrow);
gvDetails.DataSource = dt;
gvDetails.DataBind();
}
protected void gvDetails_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
CheckBox chk = (CheckBox)e.Row.FindControl("chkSelect");
if (e.Row.Cells[4].Text == "BAKHRAHAT")
{
chk.Enabled = false;
}
else
{
chk.Enabled = true;
}
}
}

Wednesday 19 June 2013

jQuery Disable Cut Copy Paste Options in Textbox

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Disable Cut, Copy and Paste Options in textbox using jQuery</title>
<script type="text/javascript" src="/jquery-1.8.2.js"></script>
<script type="text/javascript">
$(function() {
$('#txtName').bind("cut copy paste", function(e) {
e.preventDefault();
});
});
</script>
</head>
<body>
<div>
<input type="text" id="txtName" />
</div>
</body>
</html>

jQuery - Allow Alphanumeric (Alphabets & Numbers) Characters in Textbox using JavaScript

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>jQuery Allow only alphanumeric characters in textbox</title>
<script type="text/javascript" src="/jquery-1.8.2.js"></script>
<script type="text/javascript">
$(function () {
$('#txtNumeric').keydown(function (e) {
if (e.shiftKey || e.ctrlKey || e.altKey) {
e.preventDefault();
} else {
var key = e.keyCode;
if (!((key == 8) || (key == 32) || (key == 46) || (key >= 35 && key <= 40) || (key >= 65 && key <= 90) || (key >= 48 && key <= 57) || (key >= 96 && key <= 105))) {
e.preventDefault();
}
}
});
});
</script>
</head>
<body>
<div>
<b>Enter Text:</b><input type="text" id="txtNumeric" />
</div>
</body>
</html>

Get List of All Stored Procedures & Table Names from Database in SQL Server

For Storeprocedures
================
USE YourDatabaseName
SELECT * FROM SYS.PROCEDURES

For Table Names
============
USE YourDatabaseName
SELECT * FROM SYS.TABLES