Wednesday, 21 March 2012

Query String

Query String in asp.net

Query String is used to transfer the data to another page by redirecting.

Redirect Query String
Response.Redirect("aspxPage.aspx?parameter=" + TextBox1.Text);
 
Receive the Query String Value
string sQueryStringVal = Request.QueryString["parameter"];


Send and Receive a Query String using Hyperlink

SEND a Query String using Hyperlink
<asp:HyperLink ID="HyperLink1" runat="server" NavigateUrl="~/Default2.aspx?Id={0}">Link
</asp:HyperLink>

HyperLink1.NavigateUrl = string.Format(HyperLink1.NavigateUrl, TextBox1.Text);

Receive a Query String using Hyperlink
string sQueryStringVal = Request.QueryString["Id"];


Pass a Query String using Hyperlink inside the Grid View


  1. <asp:HyperLink ID="HyperLink1" runat="server" NavigateUrl='<%# "~/Default2.aspx?Id="+Eval("columnName")%>'>Link</asp:HyperLink>
     2. <asp:HyperLink ID="HyperLink1" runat="server" NavigateUrl="~/Default2.aspx?Id={0}">Link
</asp:HyperLink>

Disable Mouse Drag Event

Disable Mouse Drag Event Using J QUERY

First write a function in j query

<script type="text/javascript">
    $(document).ready(function(){
    disableDrag(document.getElementById("Drag"));
    });
   
    function disableDrag (element){
    element.draggable=false;
    element.onmousedown=function(event){
    event.preventDefault();
    return false;
    }
    }
    </script>

Then call the function in the ready function

Thank You

Send Mail Automatically in asp.net

First you include System.Net.Mail name space ..
Then you insert the below query in button click event...

try
            {
                MailMessage message = new MailMessage();
                message.From = new MailAddress("raja.com");
                message.To.Add("raja30march90@gmail.com");
                message.Subject = "Subject";
                message.Body = "Body Content";

                SmtpClient sptclt = new SmtpClient();
                sptclt.Host = "127.5.7.1";
                sptclt.Send(message);
                lblStatus.Text = "Mail send successfully";
            }
            catch (Exception e)
            {
                lblError.Text = "Mail sent Failed";
            }

Friday, 2 March 2012

Notes for ajax jquery

 GET textbox value 

TextBox in a Contentplaceholder
         Use :   $("#<%=txtRepaymentAmt.ClientID%>")

TextBox Not in a Contentplaceholder
        Use  :    $("#txt_Address")

TextBox in a gridview
    USe  :  
$("table[id*=grd_RevisedPlan] input[type=text][id*=txt_amt]") 

TextBox in a TabPanel

        Use  :
$(document.getElementById("ctl00_ContentPlaceHolder_TabContainerProduct_TabPanelSize_txtPrice"))


Get ddl value

         var getValue = $("#<%=ddlTypeId.ClientID%>").val();


Get ddl Selected text
        var getText = $("#<%=ddlTypeId.ClientID%> option:selected").text();

Split ddl selected value
       var getText = $("#<%=ddlTypeId.ClientID%> option:selected").text().split('|');
       var Text = getText [0].toString();

Set ddl selected value
       var subType = "";
       $("#<%=ddlTypeId.ClientID%>").val(subType );

Show
     $("#<%=ddlTypeId.ClientID%>").show();

Hide
     $("#<%=ddlTypeId.ClientID%>").hide();

Number validation in to textbox using Jquery

Javascript 
<script type="text/javascript">
    function numberOnlyExample() {
        if ((event.keyCode < 48) || (event.keyCode > 57))
            return false;
    }
</script> 

<asp:TextBox ID="TextBox1" onKeyPress="return validateNumbersOnly();"runat="server"></asp:TextBox>
Jquery 
<script type="text/javascript">
  $(document).ready(function () {
            $('input[numeric]').keyup(function () {
                var d = $(this).attr('numeric');
                var val = $(this).val();
                var orignalValue = val;
                val = val.replace(/[0-9]*/g, "");
                var msg = "Only Integer Values allowed.";
                if (val != '') {
                    orignalValue = orignalValue.replace(/([^0-9].*)/g, "")
                    $(this).val(orignalValue);
                    alert(msg);
                }
            });
        });

    </script>

    <asp:TextBox ID="txtCardno" numeric="integer" runat="server"></asp:TextBox>



<script type="text/javascript">
            $(document).ready(function () {

                $('#<%=txtboxId.ClientID %>').ariyValidate({
                    type: "price",
                    error_message: ""
                });

           });
</script>

Wednesday, 29 February 2012

Sql Quries

Create Table
     Create table tablename(sNo int , name nvarchar(250))

Set Primarykey
    Create table tablename(sNo int identity Primary Key, name nvarchar(250))

Set ForeignKey
   Create table tablename(sNo int identity Primary Key, name nvarchar(250) foreign key references secondTableName(columnName))

Insert query
      Insert into tableName(colName1,colName1)values(value1,value2);

Update query
     Update tableName set ColName1=value1,ColName1=value1 where Condition;

Delete query
     Delete from tableName where condition; //condition -->columnName=value        like this

Select query
     Select  * from tableName; //get all column value
     Select  tableName.columnName1,tableName.columnName1 from tableName; //get specified column only
     Select  * from tableName where Condition;// get all column value based on the condition
     Select  tableName.columnName1 from tableName; //get specified column value based on the condition

Inner  join
    Select tableName1.columnName1,tableName1.columnName2,tableName2.columnName from tableName1 inner join tableName1 on tableName1.columnName1=tableName2.columnName1

Left Outer join
Use this when you only want to return rows that have matching data in the left table, even if there's no matching rows in the right table.


   SELECT * FROM TableName1 LEFT JOIN TableName2 AS ON TableName1.Id = TableName1.Id


Right Outer join
Use this when you only want to return rows that have matching data in the right table, even if there's no matching rows in the left table.

    SELECT * FROM TableName1 RIGHT JOIN TableName2 ON TableName1.Id = TableName1.Id 

Full Outer join
Use this when you want to all rows, even if there's no matching rows in the right table.

SELECT * FROM TableName1 FULL JOIN TableName2 ON TableName1.Id = TableName2.Id

Count(*)
 If we only want to see how many records are in a table (but not actually view those records), we could use COUNT(*). COUNT(*) returns everything - including null values and duplicates.

SELECT COUNT(*) FROM Individual

Sql Ordey By
   Select * from Tablename Order By columnName

Between  for date
   select columnName from Tablename where DatecolumnName  between '4/6/2010' and '4/10/2010'

Tuesday, 28 February 2012

calculate a gridview cell values

If you want to calculate gridview cell value, you will use the foreach method .


 decimal decTotal = 0;
                foreach (GridViewRow grd in grdDetail.Rows) // grdDetail -->gridview Id
                {
                    TextBox t1 = (TextBox)grd.FindControl("txtItem");  //find the grid textboxvalue
                    TextBox t2 = (TextBox)grd.FindControl("txtQuantity");
                    TextBox t3 = (TextBox)grd.FindControl("txtPrice");
                    Label lbl = (Label)grd.FindControl("lblTotal");
                    if (t1.Text != "" || t2.Text != "" || t3.Text != "")
                    {
                        lbl.Text = Convert.ToString(Convert.ToDecimal(t2.Text) * Convert.ToDecimal(t3.Text));
                        decTotal = decTotal + Convert.ToDecimal(lbl.Text);  //add cell values
                     }
                   
               }
                lblTotal.Text = decTotal.ToString();  //store total in a label

use the above specified method . you will calculate the gridview cell values.