.Net

Using Session in asp.net :
string strName = "Raghava";
if (Session["tName"] == null)
{
 Session["tName"] = strName; 
}
else
{
   strName = Session["tName"].ToString(); 
}
txtName.Text= strName;


Using Data Cache in asp.net :

string strName = "Rajesh";
if (Cache["tName"] == null)
{
 Cache["tName"] = strName; 
}
else
{
   strName= Cache["tName"].ToString(); 
}
txtName.Text= strName;

Using Data ViewState in asp.net :

View state maintains the current state of the page,during postbacks
string strview = "Rajesh";
if (ViewState["viewName"] == null)
{
 ViewState["viewName"] = strview ; 
}
else
{
   strview = ViewState["viewName"].ToString(); 
}
txtName.Text= strview ;

Using Javascript from codebehind in asp.net :

example : This example is for showing alert.

string msgAlerta = "Session has been expire, Please login again to continue";
string alertMsga = "<script language=javascript>alert('" + msgAlerta + "');";
alertMsga += "window.location='../login.aspx'</script>";
Page.RegisterClientScriptBlock("alertMsga", alertMsga);

Row Databound in Gridview in asp.net

protected void grvflat_RowDataBound(object sender, GridViewRowEventArgs e)
{
  if (e.Row.RowType == DataControlRowType.DataRow)
  {
    DataRow dr = ((DataRowView)e.Row.DataItem).Row;
    string SFT = (dr["SFT"].ToString());
    string flaname = (dr["Flatno"].ToString());
    string phno=(dr["phoneno"].ToString());
    string cid=(dr["cid"].ToString());
    string fname = (dr["customername"].ToString());
    ((HyperLink)e.Row.FindControl("hlinkforbook")).Text = "SelectforBook";
    string url = string.Format("~/ApllicationFormSTL.aspx?flatname=" + flaname     +   "&&SFT=" + SFT+"&&phoneno="+phno+"&cid="+cid+"&&cname="+uname);

            ((HyperLink)e.Row.FindControl("Hyperlinkavail")).NavigateUrl = url;
        }
    }


Remove The Session in asp.net :
Session.Remove("strSession");

Example for Gridview in asp.net  :

 <asp:GridView ID="grvExample" runat="server" AutoGenerateColumns="False">
     <Columns>
      <asp:TemplateField HeaderText="CustomerName">
       <ItemTemplate>
           <asp:Label ID="clabe" runat="server" Text='<%#Eval("name")%>'>  </asp:Label>
                    </ItemTemplate>
                    </asp:TemplateField>
                     <asp:TemplateField HeaderText="Address">
                    <ItemTemplate>
                    <asp:Label ID="caddres" runat="server" Text='<%#Eval("addres")%>'></asp:Label>
                    </ItemTemplate>
                    </asp:TemplateField>                 
                     <asp:TemplateField HeaderText="CustomerPhoneno">
                    <ItemTemplate>
                    <asp:Label ID="phlabel" runat="server" Text='<%#Eval("phoneno")%>'></asp:Label>
                    </ItemTemplate>
                    </asp:TemplateField>                  
                 
                    <asp:TemplateField HeaderText="TeamLeadComments">
                    <ItemTemplate>
                    <asp:Label ID="temcomments" runat="server" Text='<%#Eval("temcomments")%>'></asp:Label>
                    </ItemTemplate>
                    </asp:TemplateField>
                    <asp:TemplateField HeaderText="Assign">
                    <ItemTemplate>
                    <asp:LinkButton ID="linkassign" runat="server" Text= "ReAssign" CommandArgument='<%#Eval("custid")%>' CommandName="Assign"></asp:LinkButton>
                    </ItemTemplate>
                    </asp:TemplateField>                  
                    </Columns>
                   </asp:GridView>


Get & Set the querystring values in asp.net :

Set :
Response.Redirect("test.aspx? phoneno='43434344'&mail='ex@abc.com'&name='abc' ")

Get:
phno = Request.QueryString["phoneno"].ToString();
Emailid = Request.QueryString["mail"].ToString();

Calculate Percentages in asp.net :
 
txtfirsttot.Text = txtdsctot.Text;
float salesconsider = float.Parse(txtdsctot.Text);
int dob45 = 15;
float ondate45 = salesconsider * dob45 / 100;
txtdob45.Text= ondate45.ToString();    
  

Convert the date format into dd/mm/yyyy :

string strDate = DateTime.Now.ToString("dd/MM/yyyy");


AjaxAutoComplete Extendar in asp.net :

   <asp:TextBox ID="txttestajax" runat="server"  ></asp:TextBox>
                                <ajax:AutoCompleteExtender
                                runat="server"
                                TargetControlID="txttestajax"
                                 BehaviorID="AutoCompleteEx"
                                      CompletionSetCount="20"
                                      CompletionInterval="500"
                                      EnableCaching="true"
                                      CompletionListCssClass="autocomplete_completionListElement"
                                      CompletionListItemCssClass="autocomplete_listItem"
                                      CompletionListHighlightedItemCssClass="autocomplete_highlightedListItem"
                                      DelimiterCharacters=";, :"
                                      ShowOnlyCurrentWordInCompletionListItem="true"
                                      MinimumPrefixLength="2" ServiceMethod="GetCompletionList3"
                                    UseContextKey="True">
                                  <Animations>
                    <OnShow>
                        <Sequence>
                            <%-- Make the completion list transparent and then show it --%>
                            <OpacityAction Opacity="0" />
                            <HideAction Visible="true" />                           
                            <%--Cache the original size of the completion list the first time
                                the animation is played and then set it to zero --%>                   
                       
                        <ScriptAction Script="
                                // Cache the size and setup the initial size
                                var behavior = $find('AutoCompleteEx');
                                if (!behavior._height) {
                                    var target = behavior.get_completionList();
                                    behavior._height = target.offsetHeight - 2;
                                    target.style.height = '0px';
                                }" />
                           
                            <%-- Expand from 0px to the appropriate size while fading in --%>
                                  <Parallel Duration=".4">
                                <FadeIn />
                                <Length PropertyKey="height" StartValue="0" EndValueScript="$find('AutoCompleteEx')._height" />
                                </Parallel>
                                </Sequence>
                                 </OnShow>
                                <OnHide>
                                     <Parallel Duration=".4">
                               <FadeOut />
                               <Length PropertyKey="height" StartValueScript="$find('AutoCompleteEx')._height" EndValue="0" />
                               </Parallel>
                               </OnHide>
                               </Animations>   
                                </ajax:AutoCompleteExtender>




Sending Mail using asp.net  with attachments:

using System.Net.Mail;
MailMessage mm = new MailMessage (string from, string to);
mm.Subject = "Mail from Cybercity";
mm.Body = TextBox10.Text;
mm.IsBodyHtml = true; 
mm.Attachments.Add(new Attachment(Server.MapPath("~//Brochure//layout.jpg")));
SmtpClient sClient = new SmtpClient();
sClient.EnableSsl = true;

sClient.Timeout = 400000;
sClient.Send(mm); 


AutoIncrement Id in DataTable:
DataTable dtIsolate=new DataTable();
dtIsolate.Columns.Add("EqID", typeof(int)); 
dtIsolate.Columns["EqID"].AutoIncrementSeed = 1; 
dtIsolate.Columns.Add("Equipment", typeof(string));
dtIsolate.Columns.Add("
IsolateCategory", typeof(string)); 
dtIsolate.Columns.Add("Isolated", typeof(bool));

dtIsolate.Rows.Add(dtIsolate.Rows.Count + 1,txtEq.Text, strIsolate, chkIso_action.Items[0].Selected)

Display line number in Visual Studio

Select Tools → Options → Text Editor → select the language in which you write the code → Display → Select Line Number.  
No.of visible rows with in the aspxgridview

grvCertificates.VisibleRowCount   -- -----get the no.of visible rows with in the aspxgridview 
//here grvCertificates is the devexpress gridview Id

Search

Custom Search
Protected by Copyscape Plagiarism Software