C# : Tutorial of Asp.net with c# and example

Example and code about windows application, web application, SQL, C#, WPF etc which is helpful to developer and programer.

Search This Blog

Concept of MVC (Model View Controller) in asp.net

♠ Posted by uvesh in

Definition of MVC(Model View Controller) in asp.net



MVC is one of three ASP.NET programming models. MVC is a framework for building web applications using a MVC (Model View Controller) design: The Model represents the application core (for instance a list of database records).

ASP.NET MVC gives you a powerful, patterns-based way to build dynamic websites that enables a clean separation of concerns and that gives you full control over markup for enjoyable, agile development. ASP.NET MVC includes many features that enable fast.


Models-: Model objects are the parts of the application that implement the logic for the applications data domain. Often, model objects retrieve and store model state in a database. Such as a Product object might retrieve information from a database, operate on it, and then write updated information back to a Products table in SQL Server.


In small applications, the model is often a conceptual separation instead of a physical one. For example, if the application only reads a data set and sends it to the view, the application does not have a physical model layer and associated classes. In that case, the data set takes on the role of a model object.

Views-: Views are the components that display the applications user interface. Typically, this user interface is created from the model data. An example would be an edit view of a Products table that displays text boxes, drop-down lists, and check boxes based on the current state of a Products object.


Controllers-: Controllers are the components that handle user interaction, work with the model, and ultimately select a view to render that displays UI. In an MVC application, the view only displays information; the controller handles and responds to user input and interaction. For example, the controller handles query-string values, and passes these values to the model, which in turn queries the database by using the values.


Improve Your Answer as comment below.
If our post is useful please share and comment on our post for more post and detail Visit :

http://aspdotnethelpmaster.blogspot.in/

C# : Insert data in sql database using stored Procedure in asp.net

♠ Posted by uvesh in ,

How to insert data in sql server database using asp.net and c#



First of all require to Create database, create connection, and then Following code help full to you



string constring = "Data Source=server name here.;Initial Catalog=DatabaseName;Integrated Security=True";

SqlConnection dbCon = new SqlConnection(constring);

SqlCommand sqlCmd;

DataTable dbTbl;

sqlCmd = new SqlCommand();

dbCon.Open();

sqlCmd.CommandType = CommandType.StoredProcedure;

sqlCmd.Connection = constring;


sqlCmd.CommandText = ("INSERT INTO TABLE NAME VALUES(jack,newyork,U.S.A) ");

sqlCmd.ExecuteNonQuery()

dbCon.Close();

Example of Above code

string constring = "Data Source=localhost.;Initial Catalog=Shop;Integrated Security=True";

SqlConnection dbCon = new SqlConnection(constring);

SqlCommand sqlCmd;

DataTable dbTbl;

sqlCmd = new SqlCommand();

dbCon.Open();

sqlCmd.CommandType = CommandType.StoredProcedure;

sqlCmd.Connection = constring;


sqlCmd.CommandText = ("INSERT INTO EMP  VALUES(jack,newyork,U.S.A) ");

sqlCmd.ExecuteNonQuery();

dbCon.Close();


Improve Your Answer as comment below.

If our post is useful please share and comment on our post for more post and detail Visit :


http://aspdotnethelpmaster.blogspot.in/

Asp.Net TextBox Control example with its main property


Example of Basic Textbox and its property in asp.net

The TextBox control is used to create a text box where the user can input text or symbol.


A basic TextBox as follow:


<asp:TextBox id="textbox1" runat="server" />
<br /><br />
A basic TextBox: 

A password TextBox as follow:


<asp:TextBox id="textbox2" TextMode="password" runat="server" />
<br /><br />
A password TextBox: 

A TextBox with text as follow:

<asp:TextBox id="textbox3" Text="Hello World!" runat="server" />
<br /><br />

A TextBox with text: 

A multiline TextBox as follow:

<asp:TextBox id="textbox4" TextMode="multiline" runat="server" />
<br /><br />

A TextBox with height as follow:

<asp:TextBox id="textbox5" rows="4" TextMode="multiline"
runat="server" />
<br /><br />

A multiline TextBox: 

A TextBox with width as follow:

<asp:TextBox id="textbox6" columns="20" runat="server" />

A TextBox with height: 




Improve Your Answer as comment below.

If our post is useful please share and comment on our post for more post and detail Visit :


http://aspdotnethelpmaster.blogspot.in/

How do i bind data in asp.net textbox control run time and design time and some important property of textbox

♠ Posted by uvesh in ,

Bind data in text box in code behind and in aspx means design time


Bind data in text box at design time as follow:


<asp:TextBox id="textbox1" Text="Hello World!" runat="server" />

its display: Hello World!


Bind data in text box at codeing  time or in code behind page as follow:


textbox1.text = "Hello World!"

it display as :"Hello World!"


Bind data in text box at codeing from database or data source as follow:


textbox1.text = datarow["field name of datatable or database"];

Example : textbox1.text = datarow["firstname"];

Important Property of Asp.Net Textbox control as follow:

AccessKey:specify a key that navigates to the TextBox control.

           
Example :
 

<asp:Textbox ID="txt" runat="server" AccessKey="T"  Text="<u>T</u>ext Here:"> </asp:Textbox>
here click on Alt+T you can access this textbox.

AutoCompleteType: associate an AutoComplete class with the TextBox control.


<asp:TextBox id="username" AutoCompleteType="Type" runat="server"/>

 Here Type is different type of autocomplete type such as
FirstName, LastName, MiddleName, None, Office, Email etc you need to write instead of Type any of this many more 

AutoPostBack:post the form containing the TextBox back to the server automatically when the contents of the TextBox is changed.

True if an automatic postback occurs when the TextBox control loses focus; otherwise, false. The default is false.
Example : <asp:Textbox id="Searchtxt" AutoPostBack="True" runat="server"/>

Columns:specify the number of columns to display.

Example : <asp:Textbox id="Searchtxt" Columns="3" runat="server"/>

Enabled:disable the text box.

Example : <asp:Textbox id="Searchtxt" Enabled="True" runat="server"/>

MaxLength:specify the maximum length of data that a user can enter in a text box (does not work when TextMode is set to Multiline).

Example : <asp:Textbox id="Searchtxt" maxlength="50" runat="server"/> 

ReadOnly: prevent users from changing the text in a text box.

Example : <asp:Textbox id="Searchtxt" ReadOnly="True" text="can't change" runat="server"/> 

Rows:specify the number of rows to display.

Example : <asp:Textbox id="Searchtxt" Rows="5" runat="server"/> 

TabIndex: specify the tab order of the text box.

Example : <asp:Textbox id="Searchtxt" TabIndex="5" runat="server"/> 

Wrap:specify whether text word-wraps when the TextMode is set to Multiline.

Example : <asp:Textbox id="Searchtxt" textmode="multiline" Wrap="True" runat="server"/>

Focus: set the initial form focus to the text box.

Example : <asp:Textbox id="Searchtxt" Focus="True" runat="server"/>




Improve Your Answer as comment below.

If our post is useful please share and comment on our post for more post and detail Visit :


http://aspdotnethelpmaster.blogspot.in/

Data bind in asp.net using Listview control instead of eval method

♠ Posted by uvesh in ,

Use and Importance of List View Control 


Data Binding in aps.net without Eval Bind method

The use of the Eval and Bind methods can be complicated.

This method with Data-Binding Expressions are GridView,, Repeater, and ListView. These are actually Data-Bound controls which can be bound to Data Source controls such as SqlDataSource.

Here ways to reduce the complexity of usage of the Eval method.

example of Without eval. If you are using eval method to bind data for large web applications with millions of clicks per minute, the Eval method isn’t really the perfect solution. There is everything hard-coded in HTML.

In this example, we are not going to use the Eval or Bind methods, nor are we are going to use Data Source controls. We are going to do everything from the server side.

ListView : This control has some very important event that we are going to heavily manipulate - ItemDataBound. It has templates, e.g., ItemTemplate and EditItemTemplate. Our example is going to bind the data from a DataSet, edit this data, and update it.

protected void Page_Load(object sender, EventArgs e)
{
    if (ListView.EditItem == null)
    {
        ListView.DataSource = LoadDataSet();
        ListView.DataBind();
    }
}


We are take Label controls in the ItemTemplate and TextBox controls in the EditItemTemplate. In the “edit mode”, every Label is going to be switched with a TextBox.




protected void Item_ListView_ItemDataBound(object sender, ListViewItemEventArgs e)
{

    ListViewDataItem dataItem = (ListViewDataItem)e.Item;
    DataRowView datarow_view = (DataRowView)dataItem.DataItem;
       
    if (ProductsListView.EditItem == null)
    {

        Label organization = (Label)e.Item.FindControl("organization");
        organization.Text = datarow_view["organization"].ToString();

        Label city = (Label)e.Item.FindControl("City");
        city.Text = datarow_view["City"].ToString();

        Label clientId = (Label)e.Item.FindControl("clientId");
        clientId.Text = datarow_view["clientId"].ToString();

    }

Improve Your Answer as comment below.

If our post is useful please share and comment on our post for more post and detail Visit :


http://aspdotnethelpmaster.blogspot.in/

How to bind data in checkboxlist control of asp.net? and property of checkboxlist control

♠ Posted by uvesh in ,

Checkboxlist: Creates a multi selection check box group that can be dynamically created by binding the control to a data source.

Data bind in CheckBoxList in asp.net following code for aspx page

 <asp:CheckBoxList ID="CheckBoxList1" runat="server"
   DataSourceID="SqlDataSource1" DataTextField="text" DataValueField="text">
  </asp:CheckBoxList>


Data Bind in CheckBoxList in asp.net following Code write in Code behind page



if (!IsPostback)
{

CheckBoxList1.DataSource = dataset/datatable/datasource;
CheckBoxList1.DataTextField = "tex";
CheckBoxList1.DataValueField = "text";
CheckBoxList1.DataBind();

}

Use Full Property pf asp ListBox control as follow:

AppendDataBoundItems, AutoPostBack, CausesValidation, DataTextField, DataTextFormatString, DataValueField, Items, runat, SelectedIndex, SelectedItem, SelectedValue, TagKey, Text, ValidationGroup, OnSelectedIndexChanged

Improve Your Answer as comment below.

If our post is useful please share and comment on our post for more post and detail Visit :


http://aspdotnethelpmaster.blogspot.in/

C#: How to bind radio buttonlist in asp other control like checkboxlist,listbox,dropdownlist

♠ Posted by uvesh in

asp.net controls which support data binding:

  • asp:CheckBoxList
  • asp:RadioButtonList
  • asp:Listbox
  • asp:DropDownList

The selectable items in each of the above controls are usually defined by one or more asp:ListItem controls

<html>
<body>

<form runat="server">
<asp:RadioButtonList id="countrylist" runat="server">
<asp:ListItem value="S" text="Sunday" />
<asp:ListItem value="M" text="Monday " />
<asp:ListItem value="T" text="Tuesday " />
<asp:ListItem value="W" text="Wednesday" />
<asp:ListItem value="Th" text="Thersday" />
<asp:ListItem value="F" text="Friday " />
<asp:ListItem value="S" text="Saturday " />
</asp:RadioButtonList>
</form>
</body>
</html>


Improve Your Answer as comment below.

If our post is useful please share and comment on our post for more post and detail Visit :


http://aspdotnethelpmaster.blogspot.in/