Search This Blog

Tuesday, April 19, 2011

Call popup in grid

open pop by function in grid uesing javascript.
 protected void Grid_Author_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            e.Row.Cells[8].Attributes.Add("onclick", "return ConfirmDeletion();");
        }
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            e.Row.Cells[6].Attributes.Add("onclick", "return popup("+ Grid_Author.DataKeys[e.Row.RowIndex].Value +");");
        }
    }

<script language="javascript" type="text/javascript">
function ConfirmDeletion()
{
return confirm('Are you sure you want to delete this record?');
}
function popup(getID)
{
window.open('Detail.aspx?AuthorID='+getID,'BaseWork','dialogWidth:120px;');
}
</script>
set grid property DataKeyNames=sno,title,.......
  e.Row.Cells[6].Attributes.Add("onclick", "return popup("+ Grid_Author.DataKeys[e.Row.RowIndex].Values[1] +","+Grid_Author.DataKeys[e.Row.RowIndex].Values[2] +");");

Online seo on CS page by C# code

//***********Page Title **********************************************************
        Page.Title = dr["Book_name"].ToString();
        //*********************************************************************

void _HtmlMetaTags()
    {
        HtmlMeta myMetaKeyWords = new HtmlMeta();
        HtmlMeta myMetaDescription = new HtmlMeta();
        HtmlMeta myMetaRobot = new HtmlMeta();
        HtmlMeta HTTP_EQUIV = new HtmlMeta();
        myMetaKeyWords.Name = "keywords";
        myMetaKeyWords.Content = "Non-Retail Social Investor, Institutional investor Lender, Not-For-Profit Institutions, CapitalConnect, Social Enterprise, Private Placement Market, Start-up Enterprises, exit option, Social Investment Trends, Double Bottomline, Private Equity management";
        myMetaDescription.Name = "Description";
        myMetaDescription.Content = "Social enterprise is an organisations that run Non-Retail Social Investor, Institutional investor Lender, Not-For-Profit Institutions.";
        myMetaRobot.Name = "robots";
        myMetaRobot.Content = "index,follow";
        HTTP_EQUIV.HttpEquiv = "Content-Type";
        HTTP_EQUIV.Content = "text/html; charset=iso-8859-1";
        Page.Header.Controls.Add(myMetaKeyWords);
        Page.Header.Controls.Add(myMetaDescription);
        Page.Header.Controls.Add(myMetaRobot);
        Page.Header.Controls.Add(HTTP_EQUIV);
    }

file download code in C#

 #region File download
    private void forceDownload(string filePath, bool forceDownload)
    {
        try
        {
            string path = MapPath(filePath);
            string name = Path.GetFileName(filePath);
            string extension = Path.GetExtension(filePath);
            string contentType = string.Empty;
            switch (extension.ToLower())
            {
                case ".jpg":
                    contentType = "image/JPEG";
                    break;
                case ".gif":
                    contentType = "image/GIF";
                    break;
                case ".html":
                case ".htm":
                    contentType = "image/HTML";
                    break;
                case ".pdf":
                    contentType = "Application/pdf";
                    break;
                case ".doc":
                case ".rtf":
                    //for Microsoft Word files
                    contentType = "Application/msword";
                    break;
                case ".xls":
                    //for Microsoft Excel files
                    contentType = "Application/x-msexcel";
                    break;
                case ".txt":
                    contentType = "text/plain";
                    break;
            }

            if (forceDownload)
            {
                Response.AppendHeader("content-disposition", "attachment; filename=" + name);
            }
            if (contentType != string.Empty)
                //Set the appropriate ContentType.
                Response.ContentType = contentType;
            //Write the file directly to the HTTP content output stream.
            Response.WriteFile(path);
            Response.End();
        }
        catch (Exception errmsg)
        {
            Response.Write(errmsg.Message.ToString());
        }
    }
    #endregion
    protected void LinkButtonDownLoad_Click(object sender, EventArgs e)
    {
        string filePath = ".\\uploadData\\" + LinkButtonDownLoad.Text.Trim();
        if (File.Exists(Server.MapPath(filePath)))
        {
            forceDownload(filePath, true);
        }
        else
        {
            ClientScript.RegisterStartupScript(this.GetType(), "onload", "alert('Sorry, file not found!');", true);
        }
    }
}

Call Java Script function on cs page

<script language="javascript" type="text/javascript">
function ConfirmDeletion()
{
return confirm('Are you sure you want to delete this record?');
}
</script>


if (e.Row.RowType == DataControlRowType.DataRow)
        {
            e.Row.Cells[7].Attributes.Add("onclick", "return ConfirmDeletion();");
        }

Ues of Fieldset in aspx page

<fieldset>
                            <legend>test name of heading</legend>
                                <table bgcolor="#f3e8d4" style="position: relative" width="100%">
                                    <tr>
                                        <td colspan="6" style="height: 15px" bgcolor="#ddc89d">
                                        </td>
                                    </tr>
                                    <tr>
                                        <td style="width: 179px; height: 15px">
                                            <span class="textbg">New Arrivals:</span></td>
                                        <td style="width: 389px; height: 15px">
                                            <asp:CheckBox ID="cbox_new" runat="server" Style="position: relative" /></td>
                                        <td style="width: 100px; height: 15px">
                                            Forthcoming:</td>
                                        <td colspan="3" style="height: 15px">
                                            <asp:CheckBox ID="cbox_for" runat="server" Style="position: relative" /></td>
                                    </tr>
                                    <tr>
                                        <td style="width: 179px">
                                            Best Sellers:</td>
                                        <td style="width: 389px">
                                            <asp:CheckBox ID="cbox_sell" runat="server" Style="position: relative" /></td>
                                        <td style="width: 100px">
                                            Hot Buys:</td>
                                        <td colspan="3">
                                            <asp:CheckBox ID="cbox_hot" runat="server" Style="position: relative" /></td>
                                    </tr>
                                    <tr>
                                        <td style="height: 15px;" colspan="5">
                                            If Other Language:
                                            <asp:DropDownList ID="ddl_other" runat="server" Style="position: relative" CssClass="box">
                                                <asp:ListItem Selected="True" Value="">Select</asp:ListItem>
                                                <asp:ListItem Value="1">YES</asp:ListItem>
                                                <asp:ListItem Value="0">NO</asp:ListItem>
                                            </asp:DropDownList>
                                            <asp:RequiredFieldValidator ID="val_lang" runat="server" ControlToValidate="ddl_other"
                                                ErrorMessage="Please select language." ForeColor="" Style="position: relative"></asp:RequiredFieldValidator></td>
                                        <td style="width: 100px; height: 15px;">
                                        </td>
                                    </tr>
                                    <tr>
                                        <td style="width: 179px">
                                        </td>
                                        <td style="width: 389px">
                                        </td>
                                        <td style="width: 100px">
                                        </td>
                                        <td style="width: 100px">
                                        </td>
                                        <td style="width: 100px">
                                        </td>
                                        <td style="width: 100px">
                                        </td>
                                    </tr>
                                </table>
                                </fieldset>

paging in DataList by stored procedure in SQL

CREATE procedure getQueryPageitems
 @totalItemCount int,       
 @pageNumber int,       
 @pageSize int       
as       
declare @numberOfItemToSelectForPage int       
declare @totalItemsToSel int   
declare @query nvarchar(4000)       
if(@pageSize*@pageNumber <= @totalItemCount)       
begin        
 set @numberOfItemToSelectForPage = @pageSize       
 set @totalItemsToSel = @pageSize*@pageNumber       
end       
else       
begin        
 set @numberOfItemToSelectForPage =  @totalItemCount - (@pageSize*(@pageNumber -1))      
 set @totalItemsToSel = @totalItemCount       
end   
begin
select  @query = 'select * from(select top ' + cast(@numberOfItemToSelectForPage as varchar(10))       
 + ' * from (select top ' + cast(@totalItemsToSel as varchar(10))        
+ ' * from (select * from  Query where Leedflag=1) tbl1       
    order by EntryDate desc)tabl2   order by EntryDate asc)tbl3   order by EntryDate desc'
end  
--print @query       
exec (@query)

GO

Bind Year in C#


#region BINDYEAR
    private void BINDYEAR()
    {
        try
        {
            int A = 1800;
            for (int i = 0; i < 20; i++)
            {
                ListItem LI = new ListItem();
                LI.Text = Convert.ToInt16(A).ToString();
                LI.Value = A.ToString();
                A=A+1;
                ddl_year.Items.Add(LI);
            }
            ddl_year.Items.Insert(0, "YYYY");
              
        }
        catch (Exception errmsg)
        {
            Response.Write(errmsg.Message.ToString());
        }
    }
    #endregion

Block back option in application by cache

Page load or Page init event

  Response.Cache.SetExpires(DateTime.UtcNow.AddMinutes(-1));
  Response.Cache.SetCacheability(HttpCacheability.NoCache);
  Response.Cache.SetNoStore();

How can manage length of text in C#

 #region DisplayAbout_book()
    public string DisplayAbout_book(object DataItem)
    {
        string About_book = Convert.ToString(DataBinder.Eval(DataItem, "About_book"));
        if (About_book != string.Empty)
        {
            if (About_book.Length > 75)
            {
                About_book = About_book.ToString().Substring(0, 75);
            }
            else
            {
                About_book = About_book.ToString();
            }
        }
        return About_book;
    }
    #endregion

Monday, April 4, 2011

convert multiple space in one space by function in c#

using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Text;
using System.Text.RegularExpressions;
public partial class SMS_space : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
    }
    public static string NormalizeWhiteSpace(string S)
    {
        string s = S.Trim();
        bool iswhite = false;
        int iwhite;
        int sLength = s.Length;
        StringBuilder sb = new StringBuilder(sLength);
        foreach (char c in s.ToCharArray())
        {
            if (Char.IsWhiteSpace(c))
            {
                if (iswhite)
                {
                    continue;
                }
                else
                {
                    sb.Append(" ");
                    iswhite = true;
                }
            }
            else
            {
                sb.Append(c.ToString());
                iswhite = false;
            }
        }
        return sb.ToString();
    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        //*********************its also working**********************************
        //string text = NormalizeWhiteSpace(TextBox1.Text);
        //Response.Write(text);
        //******************************8
        Regex r = new Regex(@"\s+");
        // Strip multiple spaces.
        string s3 = r.Replace(TextBox1.Text, @" ");
        Response.Write(s3);    
    }
}