Pages

Monday, June 11, 2012

How to get client IP Address

How to get client IP Address / How to get machine IP Address.



  public string  getclientIP()
        {

            ManagementObjectSearcher objSearcher = new ManagementObjectSearcher("SELECT * FROM Win32_NetworkAdapterConfiguration WHERE IPEnabled = 'TRUE'");
            ManagementObjectCollection objCollection = objSearcher.Get();
            string Ip = "";
            foreach (ManagementObject obj in objCollection)
            {           
                string[] AddressList = (string[])obj["IPAddress"];
                foreach (string Address in AddressList)
                {

                  Ip=Address;
                    break;
                }             

            }
            return Ip;
        }

Thursday, June 7, 2012

How to get public IP Address of machine



        Dim client As New WebClient()


        ' Add a user agent header in case the requested URI contains a query.
        client.Headers.Add("user-agent", "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.2; .NET CLR1.0.3705;)")

        Dim baseurl As String = "http://checkip.dyndns.org/"

        Dim data As Stream = client.OpenRead(baseurl)
        Dim reader As New StreamReader(data)
        Dim s As String = reader.ReadToEnd()
        data.Close()
        reader.Close()
        s = s.Replace("<html><head><title>Current IP Check</title></head><body>", "").Replace("</body></html>", "").ToString()
        MessageBox.Show(s)

Saturday, March 24, 2012

how to get selected item from dropdownlist in javascript


var ddl=document.getElementById ("<%=DropDownList1.ClientID%>");
var text=ddl.options[ddl.selectedIndex].text;
alert(text); 

Friday, March 23, 2012

how to add remove items in dropdown list in java script

how to add remove items in dropdown list in java script in asp.net


it is very easy to add and remove items in javascript .

Here is the code for it...



<script type="text/javascript">
    function AddItem(Text,Value)
    {
        // Create an Option object for adding item to dropdownlist       
        var opt = document.createElement("option");

        // Add an Option object to Drop Down/List Box
        document.getElementById("DropDownList").options.add(opt);
        // Assign text and value to Option object
        opt.text = Text;
        opt.value = Value;

    }<script />


Enjoyyyy Programming..

Thursday, March 22, 2012

Call JavaScript function from code behind in asp.net

It is very easy to call javascript function from code behind asp.net .


In .cs code write


  string url = "yourpage.aspx?ManiFestNumber=" + value;
                ScriptManager.RegisterClientScriptBlock(this, GetType(), "rates", "openWindow('" + url + "');", true);                  
       



in aspx page just write in this code 




<script type="text/javascript">

    function openWindow(url)
{
    var w = window.open(url, '', 'width=1,height=1,toolbar=0,status=0,location=0,menubar=0,directories=0,resizable=0,scrollbars=0');
    w.focus();
}





and Its done .........

Tuesday, March 6, 2012

Compare Validator for performing date validation


<asp:CompareValidator ID="CompareValidatorBookingDeadline" runat="server"
ControlToCompare="TextBoxTodayDate"
ControlToValidate="TextBoxExpiaryDate" Display="Dynamic"
ErrorMessage="Please check the date."
Operator="LessThanEqual"
Type="Date" 
ValueToCompare="<%= TextBoxSeminarDate.Text.ToShortString() %>">*</asp:CompareValidator>
The important thing is "ValueToCompare" property of the compare validator.

Saturday, March 3, 2012

Getting selected value from drop down using java script in asp.net



<asp:DropDownList ID="dropDown" runat="Server">

                                        <asp:ListItem Text="Item 1" Value="1" Selected="True"></asp:ListItem>

                                        <asp:ListItem Text="Item 2" Value="2"></asp:ListItem>

                                        <asp:ListItem Text="Item 3" Value="3"></asp:ListItem>

                                    </asp:DropDownList>

                                </td>

                                <td>

                                    <input type="button" value="Submit" onclick="GetDropDownValue('<%= dropDown.ClientID %>')" />




// Get DropDown value function GetDropDownValue(id) { alert(document.getElementById(id).value); }

Thursday, February 23, 2012

Math.Round() in java script

Syntax:
Math.round(x)


Example

<script type="text/javascript">

document.write(Math.round(0.75) + "<br />");
document.write(Math.round(0.50) + "<br />");
document.write(Math.round(0.25) + "<br />");
document.write(Math.round(-4.30) + "<br />");
document.write(Math.round(-4.88));

</script>


OUTPUT:


1
1
0
-4
-5

Wednesday, February 22, 2012

How to set default active view index

For making any default active view index . just write folloeing code in code behind

 WayBillMultiView.ActiveViewIndex = 0;

Tuesday, February 21, 2012

how to disable tabindex on controls in asp.net

For disabling tab just set TabIndex of any control to -1.

ex.

 <asp:TextBox ID="tbTotalAmount" runat="server" TabIndex="-1" ></asp:TextBox>

Monday, February 20, 2012

How to add Trigger to an UpdatePanel in code behind

//Creates a new async trigger
AsyncPostBackTrigger trigger = new AsyncPostBackTrigger();
            //Sets the control that will trigger a post-back on the UpdatePanel
trigger.ControlID = "btnCommit";
//Sets the event name of the control
trigger.EventName = "Click";
//Adds the trigger to the UpdatePanels' triggers collection
pnlMain.Triggers.Add(trigger);

GridView Update All Rows At Once in asp.net

private void Update()
{
StringBuilder sb = new StringBuilder();
// build the query
foreach (GridViewRow row in GridView1.Rows)
{
sb.Append("UPDATE Users SET FirstName = '");
sb.Append((row.FindControl("txtFirstName") as TextBox).Text);
sb.Append("',");
sb.Append("LastName = '");
sb.Append((row.FindControl("txtLastName") as TextBox).Text);
sb.Append("', ");
sb.Append("ClassCode = '");
sb.Append((row.FindControl("txtClassCode") as TextBox).Text);
sb.Append("'");
sb.Append(" WHERE UserID = ");
sb.Append(Convert.ToInt32((row.FindControl("lblUserID") as Label).Text));
sb.Append(" ");
}
string connectionString =
"Server=HCUBE008;Database=School;Trusted_Connection=true";
SqlConnection myConnection = new SqlConnection(connectionString);
SqlCommand myCommand = new SqlCommand(sb.ToString(), myConnection);
myConnection.Open();
myCommand.ExecuteNonQuery();
myConnection.Close();
}

Bind Data Dynamically To Drop Down List in gridview in asp.net


 ASPX Code:

 <asp:GridView ID="Gridview1" runat="server" AutoGenerateColumns="False" HeaderStyle-BackColor="#EDEDED" HeaderStyle-ForeColor="#184F46" HeaderStyle-Height="40px" HeaderStyle-HorizontalAlign="Center" OnRowDataBound="Gridview1_RowDataBound" SelectedRowStyle-BackColor="#F9CACA" ShowFooter="True" TabIndex="9" Width="100%">
<asp:TemplateField HeaderStyle-Height="30px" HeaderText="Package Type">
<ItemTemplate>
 <asp:DropDownList ID="ddlPackageType" runat="server"  Width="70px">
  </asp:DropDownList>
  </ItemTemplate>
  <HeaderStyle Height="30px" Width="8%" />
  <ItemStyle HorizontalAlign="Center" />
    </asp:TemplateField>
</GridView>


CODE Behind Code for Binding Data  :

protected void Gridview1_RowDataBound(object sender, GridViewRowEventArgs e)
        {
           
            DataSet dsPackageType = new DataSet();
      //Write Code For Getting data from Database and add it in dsPackageType Dataset .        

           if (e.Row.RowType == DataControlRowType.DataRow)
            {
                Control ctrl = e.Row.FindControl("ddlPackageType");
                if (ctrl != null)
                {

                    DropDownList dd = ctrl as DropDownList;
                    dd.DataTextField = "PackageType";
                    dd.DataValueField= "Id";
                    dd.DataSource = dsPackageType;
                    dd.DataBind();
                    dd.Items.Insert(0, new ListItem("- Select -", "0"));

                }

            }
}

How to round numbers in java Script


Option1 : Math.Round()

Jave Script For rounding the numbers to required decimals ...

<script language="javascript" type="text/javascript">
function roundNumber(rnum, rlength) { // Arguments: number to round, number of decimal places
var newnumber = Math.round(rnum*Math.pow(10,rlength))/Math.pow(10,rlength);
document.roundform.numberfield.value = parseFloat(newnumber); // Output the result to the form field (change for your
purposes)
}
</script>


Simple HTM For for Rounding the numbers 

<form name="roundform">
<table border="0" cellspacing="0" cellpadding="5">
<tr>
<td>Round:</td>
<td><input type="text" name="numberfield" value="">
to
<input name="decimalfield" type="text" value="2" size="3">
decimal places</td>



Option 2: toFixed (beta)

Java Script
<script type="text/javascript">
function roundNumber(number, decimals) { // Arguments: number to round, number of decimal places
var newnumber = new Number(number+'').toFixed(parseInt(decimals));
document.roundform.roundedfield.value = parseFloat(newnumber); // Output the result to the form field (change for your purposes)
}
</script>

Sample HTML Form 

<form name="roundform">
<table border="0" cellspacing="0" cellpadding="5">
<tr>
<td>Round:</td>
<td><input type="text" name="numberfield" value="">
to
<input name="decimalfield" type="text" value="2" size="3">
decimal places</td>













Tuesday, January 17, 2012

MX record



A mail exchanger record (MX record) is a type of resource record in the Domain Name System that specifies a mail server responsible for accepting email messages on behalf of a recipient's domain, and a preference value used to prioritize mail delivery if multiple mail servers are available. The set of MX records of a domain name specifies how email should be routed with the Simple Mail Transfer Protocol.



Wednesday, January 11, 2012

Features of SQL SERVER 2008R2



PowerPivot for SharePoint
PowerPivot for SharePoint adds shared services and infrastructure for loading, querying, and managing PowerPivot workbooks that you publish to a SharePoint 2010 server or farm. To create PowerPivot workbooks, you use PowerPivot for Excel. 


  PowerPivot for Excel
PowerPivot for Excel is an add-in to Excel 2010 that can be downloaded from the web and installed on client workstations. You use PowerPivot for Excel to assemble and create relationships in large amounts of data from different sources, and then use that data as the basis for PivotTables and other data visualization objects that support data analysis in Excel. 


  Multi-Server Administration and Data-Tier Application
The SQL Server Utility forms a central repository for performance data and management policies that tailor the operation of instances of the Database Engine that have been enrolled in the utility. It also includes a Utility Explorer for centralized management, and dashboards that report the state of the managed instances. A data-tier application (DAC) forms a single unit for developing, deploying, and managing the database objects used by an application.


  Master Data Services 
Master Data Services is comprised of a database, configuration tool, Web application, and Web service that you use to manage your organization's master data and maintain an auditable record of that data as it changes over time. You use models and hierarchies to group and organize data to prepare it for further use in business intelligence and reporting tools, data warehouses, and other operational systems. Master Data Services integrates with source systems and incorporates business rules to become the single source of master data across your organization.


  Features Supported by the Editions of SQL Server 2008 R2 
The largest database supported by SQL Server Express has been increased from 4 GB to 10 GB.


  Connecting to the Database Engine Using Extended Protection


SQL Server now supports Extended Protection, using service binding and channel binding to help prevent an authentication relay attack. Also, see Extended Protection for Authentication with Reporting Services.