Thursday, July 15, 2010

Exceptions in .NET Framework

A variety of exceptions are defined in .NET Framework under the System namespace.
These Exceptions are thrown when certain errors are found in your C# code or in the methods you call.
All of these exceptions can be caught using a catch block in C#.

Here are some of the common Exceptions:

  EXCEPTION CLASS   CAUSE OF EXCEPTION
SystemException It is used as a base class for other exceptions. Occurs on a failed run time check
AccessException Occurs when failed to access a type member (method or a field)
ArgumentException Occurs when an Argument to a method is invalid
ArgumentNullException Occurs when a null argument is passed to a method which does not accept it
ArgumentOutofRangeException Occurs when argument value is out of range
ArithmeticException Occurs due to arithmetic over-flow or under-flow
ArrayTypeMismatchException Occurs when you attempt to store different type of object in an array
BadImageFormatException Occurs when the image is in the wrong format
CoreException Its the BaseClass for the Exceptions thrown by runtime
DivideByZeroException Occurs when you attempt to divide by zero
FormatException Occurs if the format of an argument is wrong
IndexOutofRangeException Occurs when an array index is out of range
InvalidCastException Occurs when you attempt to cast to an invalid class
InvalidOperationException Occurs if a method is called at an invalid time
NotFiniteNumberException Occurs when a number is invalid
NotSupportedException Occurs if a method is not implemented by a class
NullReferenceException Occurs if you attempt to use an unassigned reference
OutofMemoryException Occurs if the memory is not enough for execution
StackOverflowException Occurs when stack overflows

Tuesday, February 9, 2010

Tab Control Using MultiView in ASP.net C#

Here I have used Menu for Tab Buttons and MultiView for Tab contents.


Add the fallowing code in the page load event and menu item click event.



protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
            MultiView1.ActiveViewIndex = 0;
        
    }
    protected void Menu1_MenuItemClick(object sender, MenuEventArgs e)
    {
        MultiView1.ActiveViewIndex = Int32.Parse(Menu1.SelectedValue);
    }







<div>
        <asp:Menu ID="Menu1" runat="server" OnMenuItemClick="Menu1_MenuItemClick" Orientation="Horizontal"
        style="left: 1px; position: relative; top: 30px" Height="38px" Width="127px" >
            <StaticMenuStyle HorizontalPadding="0px" VerticalPadding="0px" />
            <StaticSelectedStyle BackColor="#C0C0FF" BorderColor="#C0C0FF" />
           
            <Items>
                <asp:MenuItem Text="tab1" Value="0" Selected="True"></asp:MenuItem>
                <asp:MenuItem Text="tab2" Value="1"></asp:MenuItem>
                <asp:MenuItem Text="tab3" Value="2"></asp:MenuItem>
            </Items>
            <StaticHoverStyle BackColor="Silver" />
            <StaticMenuItemStyle BorderColor="#404040" BorderStyle="Solid" BorderWidth="1px" />
        </asp:Menu>
         </div>
        <div style="width: 429px; height: 191px; background-color: #C0C0FF;">
            <asp:MultiView ID="MultiView1" runat="server">
                <asp:View ID="View1" runat="server">
                   <br /> CONTENTS OF TAB1 (view1).</asp:View>
                <asp:View ID="View2" runat="server">
                    <br />
                    CONTENTS OF TAB2(view2)<br />
                </asp:View>
                <asp:View ID="View3" runat="server">
                    <br />
                    CONTENTS OF TAB3(view3)</asp:View>
            </asp:MultiView>
        </div>




Friday, February 5, 2010

Display the Cell Data of a Row in Textboxes using DropdownList for Identifying the Row

Here the dropdownlist is used to select a row through the ID column.
The selected row's cell data will be displayed on textboxes.
The database table I have used is as shown: (Table name: details1).

Bind the Dropdownlist with the ID column of the table either by using the fallowing code or by the smart task menu >> ConfigureDataSource wizard.








protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            SqlConnection con1 = new SqlConnection("your connectionstring");
            con1.Open();
            SqlDataAdapter da1 = new SqlDataAdapter("select id from details1", con1);
            DataSet ds1 = new DataSet();
            da1.Fill(ds1);
            Dropdownlist1.DataSource = ds1;
            Dropdownlist1.DataTextField = "id";
            Dropdownlist1.DataBind();
            con1.Close();
        }
protected void  DropDownList1_SelectedIndexChanged1(object sender, EventArgs e)
    {

        SqlConnection con1 = new SqlConnection("your connectionstring");
        con1.Open();
        SqlDataAdapter da1 = new SqlDataAdapter("select name,designation,place from details1 where   id=@id", con1);
        da1.SelectCommand.Parameters.AddWithValue("@id", DropDownList1.Text);
        DataTable dt1 = new DataTable();
        da1.Fill(dt1);
        con1.Close();
        DataRow row1 = dt1.Rows[0];
        txtname.Text = row1["name"].ToString();
        txtdsgn.Text = row1["designation"].ToString();
        txtplace.Text = row1["place"].ToString();

    }