Thursday, October 21, 2010

Rounded off total income

Rounded off total income
       Int32 roundedAmt;  
Int32 torounded = Convert.ToInt32(lblTotalIncome.Text);
int lastdigit = torounded % 10;
if (lastdigit >= 5)
{
roundedAmt = torounded - lastdigit + 10;
}
else
{
roundedAmt = torounded - lastdigit;
}
lblRoundedOf.Text = Convert.ToString(roundedAmt);


Thanks & Regards
Santosh

Monday, October 11, 2010

Enable and disable textbox when checked the checkbox

Here code show how enable and disble textbox when user checked the textbox.
code disble the row which contain the textbox.you can also take only checkbox
to enable and disble not neccessary to disble row.

function showHide()
{

var chkSignature = document.getElementById('ctl00_ContentPlaceHolder1_tabContainer_pnl_chkSign');
var trsign = document.getElementById('ctl00_ContentPlaceHolder1_tabContainer_pnl_trsign');
if(chkSignature.checked)
{
if(trsign != null)
{
trsign.style.display = '';
}
}
else
{
if(trsign != null)
{
trsign.style.display = 'none';
}
}
}

<tr>
<td style="height: 22px; width: 180px;">
</td>
<td align="left" colspan="3" style="height: 22px; text-align: left">
<asp:CheckBox ID="chkSignature" runat="server" Text="Show Signature" onclick="showHide()"/>
</td>
</tr>
<tr id="trsign" runat="server" style="display:none">
<td style="height: 22px; width: 180px;">
</td>
<td align="left" colspan="3" style="height: 22px; text-align: left">
<asp:TextBox ID="txtSignature" runat="server" Width="350px" TextMode="MultiLine" ></asp:TextBox>
</td>
</tr>

Thanks & Regards
Santosh

Thanks & Regards
Santosh

Sunday, October 10, 2010

Bind DropDownList using SqlDataReader

This code pulling out data from a database into a data reader is as follows.
 protected void Page_Load(object sender, EventArgs e)  
{
if (!Page.IsPostBack)
{
bindDDL();
}
}
Public void bindDDL()
{
SqlConnection con =new SqlConnection(ConfigurationManager.
ConnectionStrings["ConnectionString"].ConnectionString.ToString();)
SqlCommand cmd=new SqlCommand();
cmd.connection=con;
con.open();
cmd.commandText="SELECT Citiid,CitiName FROM tableCity";
SqlDataReader dr;
dr=cmd.ExecuteReader();
ddlname.DataSource =dr;
ddlname.DataTextField = "CitiName";
ddlname.DataValueField = "Citiid";
ddlname.DataBind();
dr.close();
con.close();
}

Thanks & Regards
Santosh

Saturday, October 9, 2010

Get duplicated record from sql server table

Here query describes how to find duplicate record from a table in sql server

SELECT User_ID FROM tbl_Member
GROUP BY User_ID
HAVING count( * ) > 1

Thanks & Regards
Santosh Singh

Friday, October 1, 2010

Refresh the aspx page automatically

This small code refresh the aspx page automatically.
Set the time according to your requirment in content="time in sec".

<head runat="server">
<title>Untitled Page</title>
<meta http-equiv="refresh" content="20" />
</head>