ASP.NET, C# - Convert string to array - Array to DataSet

by Evgelen 13. February 2010 18:17
                const string stringName = "keyword1, keyword2, keyword3";
                string[] arrayName = stringName.Split(',');

                var ds = new DataSet();
                var dt = new DataTable("Table_Name");
                ds.Tables.Add(dt);

                var dc = new DataColumn("Column_Name");
                dt.Columns.Add(dc);

                for (var i = 0; i <= arrayName.Length - 1; i++)
                {
                    var dr = dt.NewRow();
                    dr["Column_Name"] = keyw[i];
                    dt.Rows.Add(dr);
                }

                controlName.DataSource = ds;
                controlName.DataBind();

Tags: , , , , ,

ASP.NET | C# | DataSet | Array

Removes all occurrences of white space characters from the beginning and end of this instance.

by Evgelen 21. December 2009 06:07

String.Trim Method () Removes all occurrences of white space characters from the beginning and end of this instance.

[C#] 
using System;

public class TrimTest {
    public static void Main() {

        string [] temp = MakeArray();

        Console.WriteLine("Concatenating the inital values in the array, we get the string:");
        Console.WriteLine("'{0}'{1}", String.Concat(temp), Environment.NewLine);

        // trim whitespace from both ends of the elements
        for (int i = 0; i < temp.Length; i++)
            temp[i] = temp[i].Trim();

        Console.WriteLine("Concatenating the trimmed values in the array, we get the string:");
        Console.WriteLine("'{0}'{1}", String.Concat(temp), Environment.NewLine);

        // reset the array
        temp = MakeArray();

        // trim the start of the elements. Passing null trims whitespace only
        for (int i = 0; i < temp.Length; i++)
            temp[i] = temp[i].TrimStart(null);

        Console.WriteLine("Concatenating the start-trimmed values in the array, we get the string:");
        Console.WriteLine("'{0}'{1}", String.Concat(temp), Environment.NewLine);

        // reset the array
        temp = MakeArray();

        // trim the end of the elements. Passing null trims whitespace only
        for (int i = 0; i < temp.Length; i++)
            temp[i] = temp[i].TrimEnd(null);

        Console.WriteLine("Concatenating the end-trimmed values in the array, we get the string:");
        Console.WriteLine("'{0}'", String.Concat(temp));
    }

    private static string [] MakeArray() {
        string [] arr = {"  please    ", "  tell    ", "  me    ", "  about    ", "  yourself    "};
        return arr;
    }
}

Tags: , , ,

ASP.NET | C#

ASP.NET, C#, JavaScript - How to call javascript function from codebehind file?

by Evgelen 9. December 2009 18:14

Example

1. Client Side


2. Codebehind file

protected void btnSubmit_Click(object sender, EventArgs e)
{
  const string script = "";
  ClientScript.RegisterClientScriptBlock(GetType(),"ClientScript", script);
}

Tags: , ,

JavaScript

What is the Ternary Operator?

by Evgelen 29. September 2009 05:26

The ternary operator has the form condition ? value1 : value2. If the condition is true, value1 is returned; otherwise, value2 is returned. 

if (condition) return value1 else return value2;

Tags: , ,

ASP.NET | C#

How to send email using System.Net.Mail namespace?

by Evgelen 29. September 2009 04:18
// Configure mail client
SmtpClient smtpClient = new SmtpClient("SMTP server address");
smtpClient.Credentials = new System.Net.NetworkCredential("SMTP user name", ➥
"SMTP password");

// Create the mail message
MailMessage mailMessage = new MailMessage("from", "to", "subject", "body");

// Send mail
smtpClient.Send(mailMessage);

Tags: , , ,

C# | ASP.NET

Tag cloud