Wednesday, 19 August 2015

numeric textbox validation using jquery

#errmsg
{
color: red;
}

-------------------------------------

Number : <input type="text" name="quantity" id="quantity" />&nbsp;<span id="errmsg"></span>
-------------------------------------


$(document).ready(function () {
  //called when key is pressed in textbox
  $("#quantity").keypress(function (e) {
     //if the letter is not digit then display error and don't type anything
     if (e.which != 8 && e.which != 0 && (e.which < 48 || e.which > 57)) {
        //display error message
        $("#errmsg").html("Digits Only").show().fadeOut("slow");
               return false;
    }
   });
});

Thursday, 13 August 2015

gridview column total in footer row as per checkbox selection using jquery

<script type="text/javascript">
    $(function() {
        //event handler to the checkbox selection change event
        $("input[type=checkbox]").change(function() {
            //variables to store the total price of selected rows
            //and to hold the reference to the current checkbox control
            var totalPrice = 0, ctlPrice;
            //iterate through all the rows of the gridview
            $('#gvProducts tr').each(function() {
                //if the checkbox in that rows is checked, add price to our total proce
                if ($(this).find('input:checkbox').attr("checked")) {
                    ctlPrice = $(this).find('[id$= lblamount]');
                    //since it is a currency column, we need to remove the $ sign and then convert it
                    //to a number before adding it to the total
                    totalPrice += parseFloat(ctlPrice.text().replace(/[^\d\.]/g, ''));
                }
            });
            //finally set the total price (rounded to 2 decimals) to the total paragraph control.
            $('#lblTotal').text("$ " + totalPrice.toFixed(2));               
        });
    });
</script>

--------------------------------------------------------------

<asp:TemplateField>
                                            <HeaderTemplate>
                                                <asp:CheckBox runat="server" ID="chkHeader" Checked="true" OnCheckedChanged="chkHeader_CheckedChanged"
                                                    AutoPostBack="true" />
                                            </HeaderTemplate>
                                            <ItemTemplate>
                                                <asp:CheckBox ID="chk_shouldinsert" runat="server" Checked="true" ClientIDMode="Static"
                                                    CssClass="chkClass" />
                                            </ItemTemplate>
                                            <FooterTemplate>
                                                <asp:Label ID="lbltxttotal" runat="server" Text="Total" />
                                            </FooterTemplate>
                                        </asp:TemplateField>
--------------------------------------------------------------

 <asp:TemplateField HeaderText="CheckUp Amount">
                                            <ItemTemplate>
                                                <asp:Label ID="lblamount" runat="server" Text='<%# Eval("CD_SELLING_PRICE") %>' ClientIDMode="Static" />
                                            </ItemTemplate>
                                            <FooterTemplate>
                                                <asp:Label ID="lblTotal" runat="server" ClientIDMode="Static" />
                                            </FooterTemplate>
                                        </asp:TemplateField>

Sunday, 24 May 2015

datatable.select (LINQ funda)

private void PopulateGrid(GridView gv, Int32 pageindex, DataSet dsGV)
    {
        try
        {
            DataSet ds = new DataSet();
            DataTable dt = new DataTable();
            DataRow[] dr = null;

            string exp = "rowno = " + pageindex;
            if (dsGV.Tables[0].Rows.Count > 0)
                dr = dsGV.Tables[0].Select(exp);

            ds = dsGV.Clone();
            foreach (DataRow drr in dr)
                ds.Tables[0].ImportRow(drr);

            gv.DataSource = ds;
            gv.DataBind();

            //following code is written to get current level description from id_member_levels table
            //this is written to avoid join in the main query
            //if we give join in main query in Populate proceure, it affects on the performance of the query.
            if (ds.Tables[0].Rows.Count > 0)
            {
                if (cn.State == ConnectionState.Closed)
                {
                    cn.Open();
                    cm = new OleDbCommand("", cn);
                }
            }

            //for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
            //{

            //    if (ds.Tables[0].Rows[i]["MM_CURR_LEVEL"].ToString().Equals("0") == false)
            //    {
            //        strSQL = "select ML_DESC from id_member_levels where ml_level = " + ds.Tables[0].Rows[i]["MM_CURR_LEVEL"].ToString();
            //        cm.CommandText = strSQL;
            //        reader = cm.ExecuteReader();
            //        if (reader.Read())
            //            gv.Rows[i].Cells[c_Level].Text = reader["ML_DESC"].ToString();
            //        reader.Close();
            //    }
            //    else
            //        gv.Rows[i].Cells[c_Level].Text = "NA";
            //}

            if (cn.State == ConnectionState.Open)
            {
                cm.Dispose();
                cn.Close();
            }
        }
        catch (Exception ex) { lblError.Text = ex.Message; }
        finally { }
    }