Monday, December 17, 2012

Bind DropdownList using arraylist,hashtable,array

Binding with array List(vb) :

Dim AnimalArrayList as new ArrayList()
AnimalArrayList.Add("Dog")
AnimalArrayList.Add("Cat")
AnimalArrayList.Add("Elephant")
AnimalArrayList.Add("Lion")
AnimalArrayList.Add("Cat")
MyDropDownList.DataSource = AnimalArrayList
MyDropDownList.DataBind()


 Binding with Hashtable(c#)  :
Hashtable hTable = new Hashtable();

        hTable.Add("1", "Hashtable Item 1");

        hTable.Add("2", "Hashtable Item 2");

        hTable.Add("3", "Hashtable Item 3");

        hTable.Add("4", "Hashtable Item 4");



        dropHashtable.DataSource = hTable;

        dropHashtable.DataBind();
 Binding with Array(c#,vb)  :
int[] Hour = new int[24];
for (int i=0; i <=24, i++)
{
ddlHour.Items.add(Hour[i]);
}

Thursday, November 29, 2012

How to take backup of database using mysql command line

Taking backup from mysql command Line is quite simple .Just follow following steps and its done.

1)Open command prompt(run as administrator).
2)Move to the bin directory of mysql server.
3) Type following command
mysqldump -u root -p [your password] [database name for backup] -r ["filename"]
4)Dont forget to add double quotes for file name.

Note:If you dont specify path of file ,then it will go in default directory(Programfiles\Mysql\mysqlserver5.\bin).

Monday, November 26, 2012

Ajax Autocomplete

  To get autocomplete in textbox just drag a textbox to a form



Add toolkitscriptmanager.Then click on smart tag and select "Add Auto complete page method".


Now in Getcompletion list function add code for getting data from database.


 <System.Web.Services.WebMethodAttribute()> <System.Web.Script.Services.ScriptMethodAttribute()>
    Public Shared Function GetCompletionList(ByVal prefixText As String, ByVal count As Integer, ByVal contextKey As String) As String()
        Dim names As New ArrayList
        Dim db As New dataBase
        db.dbOpenConnection()
        Dim query As String = "Select username from test "
        db.cmd.CommandText = query
        Dim dr As OdbcDataReader
        dr = db.cmd.ExecuteReader
        While dr.Read()
            names.Add(dr("username").ToString())
        End While
        db.dbCloseConnection()


        Return (
            From m As String In names
            Where m.StartsWith(prefixText, StringComparison.CurrentCultureIgnoreCase)
            Select m).Take(count).ToArray()
    End Function



You can add styles to autocomplete

 <style>
For list shown
   .AutoExtender
        {
            font-family: Verdana, Helvetica, sans-serif;
            font-size: .8em;
            font-weight: normal;
            border: solid 1px #006699;
            line-height: 20px;
            padding: 10px;
            background-color: White;
            margin-left:10px;
        }
        .AutoExtenderList
        {
            border-bottom: dotted 1px #006699;
            cursor: pointer;
            color: Maroon;
        }
        .AutoExtenderHighlight
        {
            color: White;
            background-color: #006699;
            cursor: pointer;
        }
</style>


Add one div above textbox to show list
  <asp:ToolkitScriptManager ID="ToolkitScriptManager1" runat="server">
        </asp:ToolkitScriptManager>
        <br />
        <div ID="divwidth"></div>
        <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
        <asp:AutoCompleteExtender ID="TextBox1_AutoCompleteExtender" runat="server"
            CompletionInterval="100" DelimiterCharacters="" Enabled="True"
            MinimumPrefixLength="1" ServiceMethod="GetCompletionList" ServicePath=""
            TargetControlID="TextBox1" UseContextKey="True"
            CompletionListItemCssClass="AutoExtenderList"
            CompletionListCssClass="AutoExtender"
            CompletionListHighlightedItemCssClass="AutoExtenderHighlight"
            CompletionListElementID="divwidth"></asp:AutoCompleteExtender>


Friday, November 2, 2012

'System.Drawing.Image' converted to 'System.Drawing.Icon in Windows Form Application

Here Is a simple solution when you get this error.You get this error when you are trying to change icon at runtime .Here is a simple Solution to that.

Dim img As Image = 'Whatever your image is...
Dim bm As Bitmap = img
Dim hIcon As IntPtr = bm.GetHicon
Dim TheIcon As Icon = Icon.FromHandle(hIcon)

Wednesday, October 31, 2012

Seo From master page in asp.net

PRODUCT.ASPX

<!-- Replace lblProductTitle with the name of the variable that contains your product title.
Make sure the value is set in the code behind page. -->

<head runat="server">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title><%=lblProductTitle.Text%> &raquo; Test.com</title>
<meta name="description" content="Get widgets: low prices and free 
shipping at Test.com" runat="server" id="description" />

PRODUCT.ASPX.VB

'Make sure this import statement appears at the top of the page.
Imports System.Web.UI.HtmlControls



'Put this code in DataBind() or some other subroutine that runs on page load. 
'Replace lblProductTitle with the variable containing your product title.

description.Attributes("content") = " Get widgets: low prices and free shipping at 
Test.com. " & lblProductTitle.Text & "available for less."

Increase ASP.NET page timeout

 Increase timeout of page by just adding following line
 in system.web of web.config
<httpRuntime executionTimeout="600" /> <!-value is in secs-->

Tuesday, October 30, 2012

Maximum Request Length Exceeded ASP.NET

If you get this error Maximum request length exceeded while i was trying to upload several files, or a single big size file. As default, max file upload size is 4MB.
We can easily have a solution by not touching our asp.net c# or VB source code.

Just add a single line of code in your Web.config file, and you are done.


<configuration>
  <system.web>
    <httpRuntime maxRequestLength="32768" />
  </system.web>
</configuration>