Archive

Archive for the ‘Uncategorized’ Category

Removing Empty Spaces and HTML tags from TextBox text on Client Side

March 6, 2016 Leave a comment

Hi all,

Try this example for Removing Empty Spaces and HTML tags from TextBox text on Client Side

To remove spaces from textbox’s text in onblur event :

<asp:TextBox ID="TextBox2" runat="server" onblur="javascript:value=value.replace(/\s/g,'');"></asp:TextBox>

To remove HTML tags :

<asp:textbox id="TextBox2" runat="server" onblur="this.value = this.value.replace(/<\/?[^>]+>/gi, '');"></asp:textbox>

Hope this helps

Good Luck.

Categories: Uncategorized

GridView with Fixed Header and Scroll Bar

March 5, 2016 Leave a comment

Hi all,

try this example to create GridView with Fixed Header and Scroll Bar


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

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Fixed Header GridView</title>
<style type="text/css">
.FixedHeader {
position: absolute;
font-weight: bold;
vertical-align:text-bottom;
}
</style>
</head>
<body>
<form id="form1" runat="server">
<h2 align="center">GridView with Fixed Header</h2>
<div style="height: 400px; overflow: auto" align="center">
<asp:GridView ID="gvDistricts" runat="server" HeaderStyle-CssClass="FixedHeader" HeaderStyle-BackColor="YellowGreen"
AutoGenerateColumns="false" AlternatingRowStyle-BackColor="WhiteSmoke" OnRowDataBound="gvDistricts_RowDataBound">
<Columns>
<asp:TemplateField HeaderText="District ID" HeaderStyle-Width="80px" ItemStyle-Width="80px">
<ItemTemplate>
<asp:Label ID="lblDistID" runat="server" Text='<%#Eval("DistID")%>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
</Columns>
<Columns>
<asp:TemplateField HeaderText="District Name" HeaderStyle-Width="120px" ItemStyle-Width="120px">
<ItemTemplate>
<asp:Label ID="lblDistName" runat="server" Text='<%#Eval("DistName")%>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
</Columns>
<Columns>
<asp:TemplateField HeaderText="Description" HeaderStyle-Width="200px" ItemStyle-Width="200px">
<ItemTemplate>
<asp:Label ID="lblDistDesc" runat="server" Text='<%#Eval("DistDesc")%>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
</div>
</form>
</body>
</html>

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.Data;
using System.Data.SqlClient;
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
string ConStr = "Data Source=.\\sqlexpress;Initial Catalog=MYDB;Integrated Security=True";
if (!IsPostBack)
{
string Query = "SELECT * FROM Districts";
SqlConnection con = new SqlConnection(ConStr);
SqlDataAdapter adp = new SqlDataAdapter(Query, con);
DataTable dt = new DataTable();
adp.Fill(dt);
gvDistricts.DataSource = dt.DefaultView;
gvDistricts.DataBind();
}
}

protected void gvDistricts_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
if (e.Row.RowIndex == 0)
e.Row.Style.Add("height", "50px");
}
}
}

Hope this helps

Good Luck

Categories: Uncategorized

Limit Number of items to be Selected in ASP.Net ListBox

February 9, 2016 Leave a comment

Hi all,

try this example to Limit Number of items to be Selected in ASP.Net ListBox using Client and Server side validation


<script type="text/javascript" language="javascript">
function CustomValidator1_ClientValidate(source,args)
{ 
var listbox = document.getElementById("<%=ListBox1.ClientID %>");
var total = 0;
var i=0;
for( i = 0; i < listbox.options.length; i++ )
{
 if (listbox.options[i].selected) 
 {
 total ++; 
 if (total >10) {
 args.IsValid = false;
 return;
 }
 } 
 } 
 args.IsValid = true; return;
}
</script>

<asp:ListBox ID="ListBox1" runat="server" SelectionMode="Multiple" Height="100%"
Width="100%"></asp:ListBox>
<asp:Button ID="btn_Save" runat="server" Text="Save" />
<asp:CustomValidator ID="CustomValidator1" runat="server" Display="Dynamic" ErrorMessage="Please select 10 items only."
ClientValidationFunction="CustomValidator1_ClientValidate" OnServerValidate="CustomValidator1_ServerValidate">
</asp:CustomValidator>

In Code behind :

protected void CustomValidator1_ServerValidate(object source, ServerValidateEventArgs args)
{
int count = 0;
for (int i = 0; i < ListBox1.Items.Count; i++)
{
if (ListBox1.Items[i].Selected)
count++;
}
args.IsValid = (count > 10) ? false : true;
}

Hope this helps

Good Luck

Add ToolTip for DropDownList Items in ASP.Net

December 30, 2015 Leave a comment

Hi all,

Try this example to Add ToolTip for DropDownList Items in ASP.Net

<asp:DropDownList ID="DropDownList1" runat="server" ondatabound="DropDownList1_DataBound">
</asp:DropDownList>

In Code behind :

protected void DropDownList1_DataBound(object sender, EventArgs e)
{
DropDownList ddl = sender as DropDownList;
if (ddl != null)
{
foreach (ListItem li in ddl.Items)
{
li.Attributes["title"] = li.Text; // setting text value of item as tooltip
}
}
}

Hope this helps

Good Luck

Categories: ASP.Net, Uncategorized

How to Upload a SharePoint List Template

December 17, 2015 Leave a comment

Hi all,

Follow this steps to Upload List Template in SharePoint 2010

– Go to the Home of your site

– Click on Site Actions and select Site Settings

– Under Galleries select List Templates

– Click the Documents tab and select Upload Document

– Select the list template (.stp file) that you want to upload

– Now you can create a list based on your new template

Good Luck

 

JQuery to get ASP.Net DropDownList Selected item Value, Text and Index

December 14, 2015 Leave a comment

Hi all,

Try this example to use JQuery to get ASP.Net DropDownList Selected item Value, Text and Index

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>Example to get DropDownList selected item index, value and text</title>
    <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
    <script type="text/javascript">
        $(document).ready(function () {
            $('#<%=ddlWeekDays.ClientID %>').on("change", function () {
                //Get DropDownlist selected item index
                var selectedIndex = $(this).find("option:selected").index();
                //Get DropDownlist selected item value
                var selectedValue = $(this).find("option:selected").val();
                //Get DropDownlist selected item text
                var selectedText = $(this).find("option:selected").text();
                $("#spnIndex").text(selectedIndex);
                $("#spnValue").text(selectedValue);
                $("#spnText").text(selectedText);
            });
        });
    </script>
</head>
<body>
    <form id="form1" runat="server">
        <div>
            <fieldset style="width: 380px; height: 150px;">
                <legend>Get DropDownList Selected item Index, Value and Text</legend>
                <table>
                    <tr>
                        <td>Select Day:
                    <asp:DropDownList ID="ddlWeekDays" runat="server">
                        <asp:ListItem Value="0" Text="Select"></asp:ListItem>
                        <asp:ListItem Value="1" Text="Monday"></asp:ListItem>
                        <asp:ListItem Value="2" Text="Tuesday"></asp:ListItem>
                        <asp:ListItem Value="3" Text="Wednesday"></asp:ListItem>
                        <asp:ListItem Value="4" Text="Thursday"></asp:ListItem>
                        <asp:ListItem Value="5" Text="Friday"></asp:ListItem>
                        <asp:ListItem Value="6" Text="Saturday"></asp:ListItem>
                        <asp:ListItem Value="7" Text="Sunday"></asp:ListItem>
                    </asp:DropDownList>
                        </td>
                        <td>Selected Index :
                        </td>
                        <td>
                            <span id="spnIndex"></span>
                        </td>
                    </tr>
                    <tr>
                        <td></td>
                        <td>Selected Value :
                        </td>
                        <td>
                            <span id="spnValue"></span>
                        </td>
                    </tr>
                    <tr>
                        <td></td>
                        <td>Selected Text :
                        </td>
                        <td>
                            <span id="spnText"></span>
                        </td>
                    </tr>
                </table>
            </fieldset>
        </div>
    </form>
</body>
</html>

Hope this helps

Good Luck.

Categories: Uncategorized

GridView BoundField with “mailto” Email Address

Hi all,

Try this example :

<asp:BoundField DataField="Email" HeaderText="Email" SortExpression="Email" HtmlEncode="False" ReadOnly="True" DataFormatString="&lt;a href='mailto:{0}'&gt;{0}&lt;/a&gt;" />

Hope this helps

Good Luck.

Categories: Uncategorized