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];











Saturday, 6 October 2012

To Work With GridView In Outside Or Internal Event Of Any Control Except

To Work With GridView In Outside Or Internal Event Of Any Control Except


protected void txtDispQty_TextChanged(object sender, EventArgs e)
    {
 ltTotAmt.Text = "0";
    
        for (int i = 0; i < gvSaleDispatch.Rows.Count; i++)
        {
            if (((TextBox)gvSaleDispatch.Rows[i].FindControl("txtDispQty")).Text != "")
            {
                if (Convert.ToDouble(((TextBox)gvSaleDispatch.Rows[i].FindControl("txtDispQty")).Text) > Convert.ToDouble(((Label)gvSaleDispatch.Rows[i].FindControl("lblOrdQty")).Text))
                {
                    ((TextBox)gvSaleDispatch.Rows[i].FindControl("txtDispQty")).Text = "";
                    CloseWindow = "alert('Dispatch Quantity cant be greater than Ordered Quantity....');";
                    ClientScript.RegisterStartupScript(this.GetType(), "CloseWindow", CloseWindow, true);
                   
                }
                else if (Convert.ToDouble(((TextBox)gvSaleDispatch.Rows[i].FindControl("txtDispQty")).Text) > Convert.ToDouble(((Label)gvSaleDispatch.Rows[i].FindControl("lblAvailStock")).Text))
                {
                    ((TextBox)gvSaleDispatch.Rows[i].FindControl("txtDispQty")).Text = "";
                    CloseWindow = "alert('Dispatch Quantity cant be greater than Available Stock....');";
                    ClientScript.RegisterStartupScript(this.GetType(), "CloseWindow", CloseWindow, true);
                }
                else
                {
                    ((Label)gvSaleDispatch.Rows[i].FindControl("lbltot")).Text = String.Format("{0:0.00}", (Convert.ToDouble(((TextBox)gvSaleDispatch.Rows[i].FindControl("txtDispQty")).Text) * Convert.ToDouble(((Label)gvSaleDispatch.Rows[i].FindControl("lblRate")).Text)));
                    ltTotAmt.Text = String.Format("{0:0.00}", (Convert.ToDouble(ltTotAmt.Text) + Convert.ToDouble(((Label)gvSaleDispatch.Rows[i].FindControl("lbltot")).Text)));
                }
            }

        }
        ltTotPayableAmt.Text = ltTotAmt.Text;
}

Monday, 17 September 2012

Bind DropDown Under GridView

Bind DropDown Under GridView
lets go from basic...



How to bind dropdown?

Normaly We Bind A Drop Downdown In Asp.net Page Like below....
.aspx

<asp:DropDownList ID="DropDownListGroup" runat="server"
DataTextField="GroupNm" DataValueField="GroupID" Height="18px"
style="margin-bottom: 0px" Width="205px">
</asp:DropDownList>

.cs
        SqlDataAdapter adp2 = new SqlDataAdapter("select * from Group", con);
        DataSet ds2 = new DataSet();
        adp2.Fill(ds2);
        DropDownListGroup.DataSource = ds2;
        DropDownListGroup.DataBind();      
        DropDownListGroup.Items.Insert(0, "---Select---");




but in case of Grid View Thing are bit different..
You need to workout in RowDataBound Click Event

1.Bind DropDown Under GridView In Item Template

 if (e.Row.RowType == DataControlRowType.DataRow)
     {

              DropDownList drdList = (DropDownList)e.Row.FindControl("DropDownListGroup");
             SqlDataAdapter adp = new SqlDataAdapter("select * from MST_Group", con);
             DataSet ds = new DataSet();
             adp.Fill(ds);
             drdList.DataSource = ds;
             drdList.DataBind();
             drdList.Items.Insert(0, "---Select---");

             }



2.Bind DropDown Under GridView In EditItem Template

 if (e.Row.RowType == DataControlRowType.DataRow)
     {
        
if ((e.Row.RowState & DataControlRowState.Edit) > 0)
         {

             DropDownList drdList = (DropDownList)e.Row.FindControl("DropDownListGroup");
             SqlDataAdapter adp = new SqlDataAdapter("select * from MST_Group",con);
             DataSet ds = new DataSet();
             adp.Fill(ds);
             drdList.DataSource = ds;
             drdList.DataBind();
             drdList.Items.Insert(0, "---Select---");
         }
     }




3.Bind DropDown Under GridView In Footer Template

  if (e.Row.RowType == DataControlRowType.Footer)
     {

       ((Label)e.Row.FindControl("lblQty")).Text = totqty.ToString();
       TxtTotal.Text = totqty.ToString();
     
     }

Print Only Grid View in ASP.net

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