Adds

Thursday, 6 March 2014

Display Image in asp.net C# web form after click file upload using Javascript

Javascript:

<script type="text/javascript">
    function previewFile() {
        var preview = document.querySelector('#<%=Avatar.ClientID %>');
        var file = document.querySelector('#<%=avatarUpload.ClientID %>').files[0];
        var reader = new FileReader();

        reader.onloadend = function () {
            preview.src = reader.result;
        }

        if (file) {
            reader.readAsDataURL(file);
        } else {
            preview.src = "";
        }
    }
    </script>

 .aspx page code:

    <p>
        <asp:Image ID="Avatar" runat="server" Height="225px" ImageUrl="~/Images/NoUser.jpg" Width="225px" />
    </p>
    <p>
        <input ID="avatarUpload" type="file" name="file" onchange="previewFile()"  runat="server" />
        <asp:Button ID="btnUpload" runat="server" Text="Upload" OnClick="Upload"/>   
    </p>

Tuesday, 4 March 2014

Open a .aspx page on a new tab in asp.net button click event using javascript

Code For .aspx page:

<asp:Button ID="btnAbout" runat="server" Text="About" onclick="btnAbout_Click" OnClientClick="return PostToNewWindow();"/>


Java Script Function:

<script type="text/javascript">
    function PostToNewWindow() {
        originalTarget = document.forms[0].target;
        document.forms[0].target = '_blank';
        window.setTimeout("document.forms[0].target=originalTarget;", 300);
        return true;
    }
</script>


Code in .cs Page For Button Click:

protected void btnAbout_Click(object sender, EventArgs e)
{
Response.Redirect("~/About.aspx");
}

That's It.

Friday, 24 January 2014

Table Column Sum using LINQ with Where Clause

var res = (from x in dbcon.tbl_R_Bill
                where x.PartsSalesOrderSL == id
                select x.PaidAmount).Sum();

txtTotalPaidAmount.Text = res.ToString();

Sunday, 12 January 2014

Conditional count in Crystal Report XI

My Table Structure is this.
Now we will count how many student are passed & failed in the report footer. Look Like This
For This Output We need to use a Running Total Field.

Create a running total
>> Field to summarize : Result.Use Count for field.
Under Evaluate section: select "Use a formula".
Click on the icon next to this and write {result}='pass'.
Then it will only calculate the number of students Passed.
The same way applies to find the count of Failed students.

Thursday, 19 December 2013

Pass Parameter in C# DropDownList using Entity Framework

Method:



protected void LoadDropDownList(DropDownList ddl, object ds, string vf, string tf)
        {           
            ddl.DataSource = ds;
            ddl.DataValueField = vf;
            ddl.DataTextField = tf;
            ddl.DataBind();
            ddl.Items.Insert(0, new ListItem("--Select--", "0"));
        }
  

How to call this method:

LoadDropDownList(ddlRegion, r.GetAll(), "RegionID", "RegionName");



Wednesday, 11 December 2013

Add GridView Column Total in ASP.NET C#

Grid View Style(Make ShowFooter = true & Add Footer Template)

<asp:GridView ID="gvCommissionDetails" runat="server" ShowFooter="true" CssClass="gridview"
        AutoGenerateColumns="False"
        onrowdatabound="gvCommissionDetails_RowDataBound">
    <AlternatingRowStyle CssClass="gridview_alter"/>
        <Columns>
            <asp:TemplateField HeaderText="CommissionDate">
                <EditItemTemplate>
                    <asp:TextBox ID="TextBox4" runat="server" Text='<%# Bind("CommissionDate") %>'></asp:TextBox>
                </EditItemTemplate>
                <ItemTemplate>
                    <asp:Label ID="Label1" runat="server"
                        Text='<%# Bind("CommissionDate", "{0:dd-MMM-yyyy}") %>'></asp:Label>
                </ItemTemplate>
            </asp:TemplateField>
            <asp:TemplateField HeaderText="ClientCode">
                <EditItemTemplate>
                    <asp:TextBox ID="TextBox5" runat="server" Text='<%# Bind("ClientCode") %>'></asp:TextBox>
                </EditItemTemplate>
                <ItemTemplate>
                    <asp:Label ID="Label2" runat="server" Text='<%# Bind("ClientCode") %>'></asp:Label>
                </ItemTemplate>
            </asp:TemplateField>
            <asp:TemplateField HeaderText="FA">
                <EditItemTemplate>
                    <asp:TextBox ID="TextBox1" runat="server" Text='<%# Bind("FA") %>'></asp:TextBox>
                </EditItemTemplate>
                <ItemTemplate>
                    <asp:Label ID="lblFA" runat="server" Text='<%# Bind("FA") %>'></asp:Label>
                </ItemTemplate>
                <FooterTemplate>
                    <asp:Label ID="lblFATotal" runat="server"></asp:Label>
                </FooterTemplate>
            </asp:TemplateField>
            <asp:TemplateField HeaderText="UM">
                <EditItemTemplate>
                    <asp:TextBox ID="TextBox2" runat="server" Text='<%# Bind("UM") %>'></asp:TextBox>
                </EditItemTemplate>
                <ItemTemplate>
                    <asp:Label ID="lblUM" runat="server" Text='<%# Bind("UM") %>'></asp:Label>
                </ItemTemplate>
                <FooterTemplate>
                    <asp:Label ID="lblUMTotal" runat="server"></asp:Label>
                </FooterTemplate>
            </asp:TemplateField>
            <asp:TemplateField HeaderText="CO">
                <EditItemTemplate>
                    <asp:TextBox ID="TextBox3" runat="server" Text='<%# Bind("CO") %>'></asp:TextBox>
                </EditItemTemplate>
                <ItemTemplate>
                    <asp:Label ID="lblCO" runat="server" Text='<%# Bind("CO") %>'></asp:Label>
                </ItemTemplate>
                <FooterTemplate>
                    <asp:Label ID="lblCOTotal" runat="server"></asp:Label>
                </FooterTemplate>
            </asp:TemplateField>
           
        </Columns>

    </asp:GridView>

Code in .cs page


decimal totalFA = 0M;
        decimal totalUM = 0M;
        decimal totalCO = 0M;

        protected void gvCommissionDetails_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            if (e.Row.RowType == DataControlRowType.DataRow)
            {               
                decimal FACommission = Convert.ToDecimal(((Label)e.Row.FindControl("lblFA")).Text);
                totalFA += FACommission;

                decimal UMCommission = Convert.ToDecimal(((Label)e.Row.FindControl("lblUM")).Text);
                totalUM += UMCommission;

                decimal COCommission = Convert.ToDecimal(((Label)e.Row.FindControl("lblCO")).Text);
                totalCO += COCommission;
            }
            if (e.Row.RowType == DataControlRowType.Footer)
            {
                Label TotalFACommission = (Label)e.Row.FindControl("lblFATotal");
                TotalFACommission.Text = totalFA.ToString();

                Label TotalUMCommission = (Label)e.Row.FindControl("lblUMTotal");
                TotalUMCommission.Text = totalUM.ToString();

                Label TotalCOCommission = (Label)e.Row.FindControl("lblCOTotal");
                TotalCOCommission.Text = totalCO.ToString();
            }
        }