Share Your Source Code or Article

Do you have source code, articles, tutorials, web links, and books to share? You can write your own content here. You can even have your own blog.

Submit now...

Database Programming Made Easy

This tutorial will teach you step by step on how to connect and manipulate database. If you'd like to suggest a tutorial please write a comment at the bottom of this article.

Read more...

Hire Us to Do Your Work

Do you want a customized system? Do you want to setup your own website to do business? Then we are here to help you in your programming needs.

Read more...

Search

5 Tips & Tricks in ASP.NET
planetsourcecode's picture


0
Your rating: None
Language: 

Trick #1 Delete a selected row from a DataGrid using c#

Double click the dataGrid and write the code

  1. private void DataGridvie_selected(Object sender,EventArgs e)
  2. {
  3. DataSet da=new DataSet();
  4.  
  5. int i=datagrid1.selectedIndex;
  6.  
  7. int empidval=ds.Tables["emp"].Rows[i][0].ToString();
  8.  
  9. SqlConnection conn=new Sqlconnection("conn string");
  10. conn.Open();
  11. SqlCommand cmd=new SqlCommand("delect emp where empid="+empid+"",conn);
  12. cmd.ExecuteNonQuery();
  13. MessageBox.Show("Row Deleted");
  14. }

Trick #1 How to Validate DataType only with a CompareValidator

Let's say you have a textbox in which you need to make sure the user puts in a valid date. You can actually use a CompareValidator Control for this - - it's so simple.

All you need to do is add the ControlToValidate property (the control/textbox in which a date must be entered), the erroressage you need (ErrorMessage property), the Operator property(change to DataTypeCheck), and the Type property (choose Date).

  1. <asp:CompareValidator id=cv1
  2. Type="Date" Operator="DataTypeCheck"
  3. ErrorMessage="Must be a valid date" Display="Dynamic"
  4. ControlToValidate="txtDate"
  5. runat="server" />

Trick #3 Difference between two dates in C#

  1. public int GetTotalDays(DateTime startedDateTime)
  2.  
  3. {
  4.  
  5. //get the current date
  6.  
  7. DateTime nowDate = System.DateTime.Now;
  8.  
  9. System.TimeSpan span = nowDate - startedDateTime;
  10.  
  11. int days = (int)span.TotalDays;
  12.  
  13. return days;
  14.  
  15. }

Trick #4 Difference between Convert.ToInt32(string) and Int32.Parse
Convert.ToInt32(string) and Int32.Parse(string) yield identical results except when the string is actually a null. In this case, Int32.Parse(null) throws an ArgumentNullException; but, Convert.ToInt32(null) returns a zero. So it is better to use Int32.Parse(string)

Trick #5 Display Particular Format for Phone Number

Let's say your database stores phone numbers without the dashes or parentheses, but you would like to display it like that, on the web page.

To do this, store the number as an integer, and then, the following code snippet will do the trick:

  1. Dim s as integer="1234567891"
  2. label1.text=string.Format("{0:(000)000-0000}",s)

wait for much more tips and tricks

About the author:

PlanetSourceCode.in is a place for all developer providing free source codes, articles, complete projects,complete application in PHP, C/C++, Javascript, Visual Basic, Cobol, Pascal, ASP/VBScript, AJAX, SQL, Perl, Python, Ruby, Mobile Development




Post new comment

  • Web page addresses and e-mail addresses turn into links automatically.
  • Lines and paragraphs break automatically.
  • You can enable syntax highlighting of source code with the following tags: <code>, <blockcode>, <asp>, <c>, <cpp>, <csharp>, <css>, <java>, <java5>, <javascript>, <mysql>, <php>, <sql>, <vb>, <vbnet>. The supported tag styles are: <foo>, [foo].
  • You may use [inline:xx] tags to display uploaded files or images inline.
  • Links to specified hosts will have a rel="nofollow" added to them.

  • You may insert videos with [video:URL]

More information about formatting options

CAPTCHA
This question is for testing whether you are a human visitor and to prevent automated spam submissions.
Image CAPTCHA
Enter the characters shown in the image.

Step by Step Java Tutorial

In this tutorial you will learn how to program with Java. It has a rich of information to be educated well with Java.

Read more...

Do You Have Question?

Do you have any question related to computer programming? Visit our forum and post new topic on the category you like. Be gentle when asking a question.

Ask now...

Point of Sale

Point of Sale is very useful especially for supermarkets or restaurants. I have included a barcode scanner in this program. Please check it out.

Read more...