Strongly typed DataSets
are merely generic DataSets that have their columns and tables defined in
advance, so the compiler already knows what they will contain.
1.Open Visual Studio, and create a new ASP.NET web site.
2.In Solution Explorer, right-click to add a new item,
and select DataSet. Visual Studio will recommend placing the DataSet
file inside the App_Code folder, which you should allow it to do for you.
3.The DataSet1.xsd will open in design mode, and the TableAdapter
Configuration Wizard will be launched. For now, just click Cancel, because you
will add tables by dragging them from the Server Explorer.
4.Locate the Server Explorer Toolbox, navigate to your
SQL Server 2005 database,
5.Drag the dbo.empuserdetails table to your DataSet
Designer window. The window should now resemble Figure.
As you can see from Figure 1, for each table
that is added to the designer, Visual Studio creates a strongly typed DataTable
and a TableAdapter.
The DataTable has all of its columns already defined. The
table
adapter is the object you will use to fill the table. By default, you
have a Fill()
method that will find every row from that table.
This strongly typed DataSet,
as is, will return all of the records in the Product table.
Since the Empuser
table contains a lot of information, let us modify the default query to
return
only the employee that belong to the given empid. To do this,
right-click the empuserdetailsTableAdapter and select Add Query. Pick
Use SQL
statements and click the Next button. Then, choose SELECT, which returns
rows,
and click Next. Finally, enter the following query in the window
SELECT Empid, Username, Password
FROM dbo.Empuserdetails
Where Empid= @Empid
Place a GridView in default.aspx
The Code in Default.aspx.cs is given below
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
DataSet1TableAdapters.EmpuserdetailsTableAdapter adas=
new DataSet1TableAdapters.EmpuserdetailsTableAdapter ();
DataSet1.EmpuserdetailsDataTable table=adas.GetData();
///
/// Summary description for Class1
///
public class Class1
{
SqlConnection con = new SqlConnection(@"Data Source=INDIA\SQLEXPRESS;Initial catalog=ani;integrated security=true");
public Class1()
{
//
// TODO: Add constructor logic here
//
}
public DataTable selec()
{
SqlDataAdapter da = new SqlDataAdapter("select * from aa", con);
DataSet ds = new DataSet();
da.Fill(ds,"gg");
return ds.Tables["gg"];
}
public void up(string name, int age,int id)
{
SqlCommand cmd = new SqlCommand("update aa set name='" + name + "',age=" + age + " where id=" + id + "", con);
con.Open();
cmd.ExecuteNonQuery();
con.Close();
}
}
ImageButton1_Click on Gridview
protected void ImageButton1_Click(object sender, ImageClickEventArgs e)
{
ImageButton imgbtn = (ImageButton)sender;
GridViewRow grdRow = (GridViewRow)imgbtn.NamingContainer;
LinkButton name = (LinkButton)imgbtn.FindControl("controlIdName");
Label tId = (Label)imgbtn.FindControl("Label1");
string ab = tId.Text;
DataList Control of ASP.Net 2.0 provides the functionality to display the data in form of ordered or unordered list of items. DataList control includes different types of templates that also enable you to select, edit, update or delete the data items. You can organize the data items bound to the DataList control using simple HTML markup tags inside the templates. ItemTemplate field is the most necessary element of the DataList control that enables you to display the retrieved data items from any datasource. There are style templates also that can be used to customize the appearance of list items of DataList. Following are the types of templates of ASP.Net 2.0 DataList control:
1. ItemTemplate: This is the main template that displays the data content retrieved from the datasource in the specified layout and CSS style applied to it. ItemTemplate is the required template of DataList control.
2. AlternatingItemTemplate: You can define the alternate style for the data content that is to be displayed inside the DataList. Alternate template renders the data items according to the specified layout and appearance styles associated to it. If AlternateTemplate is not defined then DataList control renders the ItemTemplate only.
3. SeparatorTemplate: It allows you to separate the repeat layout of list items inside the DataList control. SeparatorTemplate renders the specified separator character, text or any HTML markup tag between items as well as alternating items.
4. SelectedItemTemplate: It displays the content with specified style and layout applied to the selected item template. SelectedItemTemplate renders only when selected index changed event of DataList control fires.
5. EditItemTemplate: You can place the textbox controls inside this template for the data fields to allow the users to update the old value with new one. EditItemTemplate renders when DataList control receives the edit command event signal.
6. HeaderTemplate: You can display the heading at the top of list items by specifying customized appearance for the header text.
7. FooterTemplate: Similar to HeaderTemplate you can also add the footer text with customized appearance under the DataList control’s data items.
State management is defined as a process of maintaining state and page information over multiple page requests.
2 Types:-
Client side State Management
View state
Hidden fields
Cookies.
Query String
The ViewState property provides a dictionary object for retaining values between multiple requests for the same page. The ViewState indicates the status of the page when submitted to the server.The status is defined through a hidden field placed on each page.
The Hidden fieldstores a variable in its value property and is explicitly added to the page.
A Cookie is a small amount of data that is stored in the client machine or in the memory of a client browser session. It contains site specific information that the server sends to the client along with a page output. Cookies can be temporary or have specific expiration dates. protected void Page_Load(object sender, EventArgs e)
{
HttpCookie c = new HttpCookie("my cookie");
c.Value = "hello";
c.Expires = System.DateTime.Now.AddDays(7);
Response.Cookies.Add(c);
Query string is the limited way to pass information to the web server while navigating from one page to another page. This information is passed in url of the request.
protected void Page_Load(object sender, EventArgs e)
{
Response.write(Request.Querystring["name"].ToString());
Response.write(Request.Querystring["pwd"].ToString());
} Sever side State Management
Application
Session
The Application state is a key value dictionary structure that is created during the page request to a URL. Application specific information can be added to this structure and stored between page requests.
The Session state is scoped to the current browser session and the number of session states will be determined by the number of users using the application. The session can be different for each visit by the user.