Sunday, 6 July 2014

String First And Last Character by Substring in C#

Let say you have a string and you want its first or last character like first 2 or last 4 how could you do that?

here is sample for that


string mystring = "122014";
      
        mystring = mystring.Substring(mystring.Length - 4);
        Response.Write(mystring.ToString());


//output:2014


 mystring = "122014";
        string sub = mystring.Remove(mystring.Length - 4);
        Response.Write("<br>");
        Response.Write(sub.ToString());


//output: 12

Wednesday, 12 June 2013

Add / Change Rdlc at Runtime


Add / Change Rdlc at Runtime

            reportViewer1.LocalReport.EnableExternalImages = true;        
            reportViewer1.LocalReport.ReportEmbeddedResource = "ChequePrint.Report.Report1.rdlc";
            this.DataTable1TableAdapter.Fill(this.ChecqueDetail.DataTable1);
            this.reportViewer1.RefreshReport();


As you'll see in
reportViewer1.LocalReport.ReportEmbeddedResource = "ChequePrint.Report.Report1.rdlc";

ChequePrint.Report.Report1.rdlc is just a text of rdlc file path,and i got it from,







on report viewer click on top right side small button (step 1) and view the report list f




Sunday, 10 February 2013

Working With DateTime In SQL and C#

Date Time Format In C# and SQL







In ASP.net C#

compare two date like TextBoxToDate and TextBoxToDate

DateTime org = DateTime.ParseExact(TextBoxToDate .Text,"dd/MM/yyyy",null);
DateTime enter = DateTime.ParseExact(TextBoxToDate.Text, "dd/MM/yyyy", null);

if(enter.Date<org.Date)
        {
//do what you wish          
        }


       

Monday, 4 February 2013

Selection In GridView With CheckBoxes


CheckBoxes Wise Selection In GridView in just 3 steps







1)In ASPX side
 your grid view must contain DataKeyNames
 and checkbox under templatefield

 <asp:GridView ID="GridViewtemp" runat="server"   DataKeyNames="Person_Id">



2)Now you have above grid where so many rows are avail and each row has a checkbox in it(as we placed a checkbox in templatefield's item template)

now when user click on these checkboxes and make out his selection we will provide him further a button 'btnselect' which will again bind a grid and show you only those selected row which were checked previously.

3)So On that btnselect_click event




In C# On Button Click

 protected void btnselect_Click(object sender, EventArgs e)
     {
       

    
             for (int i = 0; i < GridViewtemp.Rows.Count; i++)
             {
                 if (((CheckBox)GridViewtemp.Rows[i].FindControl("chkSONo")).Checked == true)
                 {
                     soid = ((Label)GridViewtemp.Rows[i].FindControl("
lblPersonid")).Text;


                     if (value == "")
                     {
                         value = soid;
                     }
                     else
                     {
                         value = value + "," + soid;
                     }


                 }

             }
             BindItemGrid(soid);
            
       
     }
     public void BindItemGrid(string Key)
     {
         query = " select * from tb_Stamping  where   [Person_Id] in (" + value + ")";
         SqlDataAdapter adp = new SqlDataAdapter(query, con);
         DataSet ds = new DataSet();
         adp.Fill(ds);
         gvselectcontent.DataSource = ds;
         gvselectcontent.DataBind();

     }

Tuesday, 22 January 2013

Gradient Text Effect or Button CSS Sample

Gradient Texture In Button or Text

If u guys are looking stuff like you want to gradient effect to a text or button .
then below is the simple code without much bugs.











<style>
h1 {
  font-size: 72px;
  background: -webkit-linear-gradient(#eee, #333);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}
.clr {
  font-size: 72px;
  background: -webkit-linear-gradient(#eee, #333);
  -webkit-background-clip:button;
  -webkit-text-fill-color: transparent;
}

.clrtwist {
  font-size: 72px;
  background: -webkit-linear-gradient(#333,#eee );
  -webkit-background-clip:button;
  -webkit-text-fill-color: transparent;
}</style>


<h1>vijay negi and the gradient!</h1>
    <input id="Button1" class="clr" type="button" value="button" />
        <input id="Button2" class="clrtwist" type="button" value="button" />

below one is the output



Monday, 14 January 2013

SQL Transaction In C#,ASP.Net

 Transaction In C#,ASP.Net
 



SqlTransaction transaction;
con.Open();
transaction = con.BeginTransaction();
try
{
for (int i = 0; i < dtTemp.Rows.Count; i++)
{
SqlCommand cmd = new SqlCommand("insert command....", con,transaction);
cmd.ExecuteNonQuery();
}
transaction.Commit();
}

catch (Exception Error)
{


}

In above Part the only thing you have to care about is

SqlTransaction transaction;
con.Open();
transaction = con.BeginTransaction();
try {
  SqlCommand cmd = new SqlCommand("insert command....", con,transaction);
cmd.ExecuteNonQuery();
transaction.Commit();                    //whenever you call commit it means now finaly
                                                       //all execution will take place else rollback to catch
}
catch
{
  transaction.Rollback(); 

Thursday, 27 December 2012

Autocomplete Extender AJAX


Alternate use of  AutoComplete Extender AJAX




For searching what we basically need is  name and id behind it.
so for that we must have a
searcher :textbox(txtSearch)
id holder when search complete:hiddenfield(hfCustomerId)


Htmil Source Side


<script type = "text/javascript">

                      function ClientItemSelected(sender, e) {

                          $get("<%=hfCustomerId.ClientID %>").value = e.get_value();

                      }

    </script> 

Search by Client: 

                <asp:HiddenField ID="hfCustomerId" runat="server" />

                <asp:TextBox ID="txtSearch" runat="server" Width="200"></asp:TextBox>

                <asp:AutoCompleteExtender ID="AutoCompleteExtender2" runat="server" 

                    BehaviorID="AutoCompleteEx" CompletionInterval="100" 

                    CompletionListCssClass="completionList" 

                    CompletionListHighlightedItemCssClass="itemHighlighted" 

                    CompletionListItemCssClass="listItem" CompletionSetCount="20"  OnClientItemSelected="ClientItemSelected"

                    DelimiterCharacters=";, :" EnableCaching="true" MinimumPrefixLength="1" 

                    ServiceMethod="GetClientList" ShowOnlyCurrentWordInCompletionListItem="true" 

                    TargetControlID="txtSearch" UseContextKey="True">

                </asp:AutoCompleteExtender>






Code Behind

Web Method to process autocomplete with textbox



Instead this (used for singal value)



SqlConnection con = new SqlConnection(ConfigurationManager.AppSettings["ALPHAconnString"]);

        SqlCommand cmd = new SqlCommand("SELECT distinct [Company_Name],Client_id FROM Client where Company_Name like '" + prefixText + "%' ", con); 

        if (con.State == ConnectionState.Closed)

            con.Open();

        cmd.CommandType = CommandType.Text;

        SqlDataReader dr = cmd.ExecuteReader();

       



        while (dr.HasRows)

        {

            while (dr.Read())

            {

                string item = AjaxControlToolkit.AutoCompleteExtender.CreateAutoCompleteItem(dr["Company_Name"].ToString(), dr["Client_id"].ToString());

                items.Add(item);



                //items.Add(dr.GetValue(0).ToString());



            }

            dr.NextResult();

        }

        return items.ToArray();







Use this(to hold two value)





SqlConnection con = new SqlConnection(ConfigurationManager.AppSettings["ALPHAconnString"]);

       
 SqlCommand cmd = new SqlCommand("SELECT distinct 
[Company_Name],Client_id FROM Client where Company_Name like '" + 
prefixText + "%' ", con); 

        if (con.State == ConnectionState.Closed)

            con.Open();

        cmd.CommandType = CommandType.Text;

        SqlDataReader dr = cmd.ExecuteReader();

       



        while (dr.HasRows)

        {

            while (dr.Read())

            {

               
 string item = 
AjaxControlToolkit.AutoCompleteExtender.CreateAutoCompleteItem(dr["Company_Name"].ToString(),
 dr["Client_id"].ToString());

                items.Add(item);



                //items.Add(dr.GetValue(0).ToString());



            }

            dr.NextResult();

        }

        return items.ToArray();







after searching from textbox ,on any button Click


string clientid= Request.Form[hfCustomerId.UniqueID];











Print Only Grid View in ASP.net

ASP.net How to Print Only GridView < div id ="gridviewDiv" >   < asp:GridView ID ="gridViewToPri...