Tuesday, March 22, 2011

DropDownList Compare Validation

DDLModality.Items.Insert(0, "Select");

<asp:CompareValidator ID="ReqReportType" runat="server" ControlToValidate="DDLReportType" ValidationGroup="Date" ErrorMessage="*" Operator="NotEqual" ValueToCompare="Select"/>


ddlPackageName.Items.Insert(0, new ListItem("Select", "0"));

<asp:CompareValidator ID="CmpPackageName" runat="server" ControlToValidate="ddlPackageName"
                                ValidationGroup="Orgnizer" ErrorMessage="*" Operator="NotEqual" ValueToCompare="0">
                                <asp:Image ID="I1" runat="server" Height="20px" Width="20px" ImageUrl="~/App_Themes/Images/Cancel.png" />
                            </asp:CompareValidator>

PopUp Print Automatically

function popupprint() {
            var prtContent = document.getElementById('<%=content.ClientID %>');
            var WinPrint = window.open('', '', 'letf=0,top=0,toolbar=0,scrollbars=0,status=0');
            WinPrint.document.write(prtContent.innerHTML);
            WinPrint.document.close();
            WinPrint.focus();
            WinPrint.print();
            WinPrint.close();
        }

Friday, March 18, 2011

Open Page as New Window with Full Screen From Code Behind

Full Screen:

ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "test", "window.open('"+Test.aspx+"','1','');", true);

Set Width and Height:


ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "test", "window.open(Test.aspx?No=" + T1.Text.ToString() + "','1','height=800,width=900px');", true);

How to Get Data Table Rows Values

Name Is the Column Name What Have in DataBase

dt.Rows[0]["Name"].ToString();

Grid View Row Data Bound

protected void Grd_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            Image ImageShow = (Image)e.Row.FindControl("imgGrid");
            if (e.Row.RowType == DataControlRowType.DataRow)
            {
                string StatusShow = Grd.DataKeys[e.Row.RowIndex]["StatusShow"].ToString();
                if (StatusShow == "OLD")
                {
                    ImageShow.ImageUrl = "~/App_Themes/Images/Ok.png";
                }
                else
                {
                    ImageShow.ImageUrl = "~/App_Themes/Images/Cancel.png";
                }
            }
        }

How to Convert Grid View Rows as XML String

public string ConvertCircleXML()
        {
            StringBuilder sb = new StringBuilder();
            sb.Append("");
            sb.Append("<Circle>");
            foreach (GridViewRow Item in GrdCircle.Rows)
            {
                CheckBox GrdChkBox = (CheckBox)(Item.FindControl("ChkCircle"));
                if (GrdChkBox.Checked == true)
                {
                    sb.Append("<test>");
                    string CircleId = GrdCircle.DataKeys[Item.RowIndex].Values[0].ToString();
                    string CorpBillingId = GrdCircle.DataKeys[Item.RowIndex].Values[1].ToString();
                    TextBox TxtGrdBillingName = (TextBox)(Item.FindControl("TxtBillingName1"));
                    TextBox TxtGrdBillingAmount = (TextBox)(Item.FindControl("TxtBillingAmount1"));
                    sb.Append("<CircleId>" + CircleId + "</CircleId><CorpBillingId>" + CorpBillingId + "</CorpBillingId><TxtGrdBillingName>" + TxtGrdBillingName.Text + "</TxtGrdBillingName><TxtGrdBillingAmount>" + TxtGrdBillingAmount.Text + " </TxtGrdBillingAmount><UserId>" + Session["UserId"].ToString() + "</UserId>");
                    sb.Append("</test>");
                }
            }
            sb.Append("</Circle>");
            return sb.ToString();
        }

How to Get Grid View Data Keys Values From Using foreach GridViewRow

        protected void BtnCentre_Click(object sender, EventArgs e)
        {
           
            foreach (GridViewRow Item in GrdCentre.Rows)
            {
                CheckBox GrdChkBox = (CheckBox)(Item.FindControl("ChkCentre"));
                if (GrdChkBox.Checked == true)
                {
                    string CircleId = GrdCentre.DataKeys[Item.RowIndex].Values[0].ToString();
                    string CenterId = GrdCentre.DataKeys[Item.RowIndex].Values[1].ToString();
                    string CorpBillingId = GrdCentre.DataKeys[Item.RowIndex].Values[2].ToString();
                }
            }
        }

Calculate Sum Column Values and Show in Grid View Footer

protected void myview_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            if (e.Row.RowType == DataControlRowType.DataRow)
            {
                _DueAmount = _DueAmount + Convert.ToDouble(DataBinder.Eval(e.Row.DataItem, "Due")); // Due is DataField
                _NetAmount = _NetAmount + Convert.ToDouble(DataBinder.Eval(e.Row.DataItem, "NetAmount")); // NetAmount is DataField
            }
            if (e.Row.RowType == DataControlRowType.Footer)
            {
                e.Row.Cells[7].Text = "Total Rs: ";
                e.Row.Cells[8].Text = Convert.ToString(_DueAmount);
                e.Row.Cells[9].Text = Convert.ToString(_NetAmount);               
            }
        }

How to Call Client Side Script From Server Side

Here Name is Nothing You Can Give Any Name

YesNo() is the Script Name

ScriptManager.RegisterStartupScript(this, this.GetType(), "Name", "YesNo();", true);


Example

function YesNo() {
            var answer = confirm("Yes?")
            if (answer) {
                StartPrintScreen();
            }
            else {
                return false;
            }
        }


If Condition is Satisfy This Belos function will Call and Open Page In New Window


function StartPrintScreen() {
            var _Id= document.getElementById('HdnId').value;
            window.open("ashok.aspx?Id=" + _Id, '', 'toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=no,width=800,top=0,left=100');
        }

Script Alert From Code Behind

Add This Method In Your Aspx.cs Page and Call where You want to Alert

public void ScriptAlert(string Message)
{
string alertScript = "javascript: alert('" + Message + "')";
ScriptManager.RegisterStartupScript(this, this.GetType(), "alertScript", alertScript, true);
}

Example:
ScriptAlert("Test");