Wednesday, December 17, 2014

Tips for Asp.Net

How to assign RequiredFiled Validator for DropDownList in Asp.Net

 <form id="form1" runat="server">
            Select Gender :
            <asp:DropDownList runat="server" ID="ddlList">
                <asp:ListItem Text="Select" Value="0"></asp:ListItem>
                <asp:ListItem Text="Male" Value="1"></asp:ListItem>
                <asp:ListItem Text="Female" Value="2"></asp:ListItem>
            <asp:RequiredFieldValidator runat="server" ID="rfv" ControlToValidate="ddlList" ForeColor="Red" InitialValue="0" ErrorMessage="Please Select Gender"></asp:RequiredFieldValidator><br />
        <asp:Button  runat="server" ID="btnsubmit" Text="Submit" />

Thursday, October 30, 2014

Validating CheckBox Selected or Not In Gridview Before Submitting Page.

Validating CheckBox ie Selected Or Not in Gridview before submitting page and if not showing alert message to user using javascript.

In Default.aspx

In <body> tag

Monday, October 20, 2014

How to pass multiple QueriesString in HyperLink in GridView.

In Example.aspx

Add following HTML part in <body> Tag

 <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False"  Width="100%">
<asp:TemplateField HeaderText="Register Date" ItemStyle-HorizontalAlign="Center" ItemStyle-Width="65px">
<asp:Label ID="lbldate" runat="server" Text='<%#Eval("LoginDate","{0:MM/dd/yyyy }")%>'></asp:Label>
<asp:TemplateField HeaderText="Edit" ItemStyle-HorizontalAlign="Center">

Monday, October 13, 2014

How to Maintain State of FileUpload Control in Asp.Net

Generally when we upload any file using FileUpload Control and if their is TextBox with TextChange Event ,When TextChange Event fires the file from FileUpload  Control will looses file due to postback,, on PostBack PostedFile property gets initilized with HttpPostedFile object for the file. As we know that http request can't maintain state, and PostedFile is initilized with HttpPostedFile Object so it loose it's state.

By using State Managment Techniques we maintain File in FileUpload Control.

Lets Design one Page with FileUpload Control,Label, TextBox and Button.

Friday, October 10, 2014

Difference Between HashTable and Dictionary in C#

Both HashTable and Dictionary stores values in form of Key-Value pairs,To access the values from Hash Table or from Dictionary we use Key to get value.But their are other difference between HashTable and Dictionary shown below.

HashTable :

  • Hash table is not a generic type.
  • Hashtable is a collection of data structures to hold data as key-value pairs.
  • The Hashtable is a weakly typed data structure, so you can add keys and values of any Object Type to the Hashtable.
  • In Hashtable boxing/unboxing (valuetypes need boxing) will happened and which may have memory consumption
  • When we add values to HashTable the order of values is not maintained while retrieving.

Monday, October 6, 2014

How to Bind 2 or more columns data from database table to DropDownList in

In DropDownList everyone knows that there is DataTextField and DataValueField commonly we bind one column to DataTextField and one column to DataValueField from DataTable or any DataReaders etc.
If we want to bind 2 or more columns to DataTextField of DropDownList we use Dictionary Class and by using that we bind to dropdownlist.

In Default5.aspx Page

Add one DropDownlist to a page as shown in below.

Wednesday, October 1, 2014

How to Add Colmns to DataTable and adding Some rows to it and binding to Gridview

In aspx.cs

Adding rows using code to DataTable

using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;