-->

Friday, December 25, 2015

How to bind Bulleted List control in asp.net

Following some steps for binding bulleted list control using SqlDataSource

In this article, I will show you, How to bind BulletedList in ASP.NET. In this article, I will take SQL DataSource control to bind it. ASP.NET Provide inbuilt control to bind any other control like ListBox, ComboBox, BulletedList. After bind it, it will look like list of unordered list of HTML.Lets  to Start how to bind it. I will Give you, video as well as code for this.




Step-1 : Open visual studio
Step-2:  Click  File-->New-->WebSite
starting screen

Step-3: Right click on website name in solution explorer, Add-->Add new item 

web form


Step-4: Make Database table 
Step-5: Drag Bulleted list from toolbox and drop on design window.
Step-6: Select Show smart tag of Bulleted list
show smart tag

Step-7: On Bulledted list task click choose data source link
Step-8: Select New DataSource from Data Source configuration wizard.

choose data source

Step-9: Select SQL Database from Data Source Configuration wizard. and click ok button

data configuration wizard

Step-10 : Select existing database from configure data source.

connection string property

Step-11 : Change Connection name according to you and click ok
web.config file

Step-12 : Select table from name ,select table field name and press ok button

table view

Step-13: Click test query button and finish the process
Step-14: Select a data field to display in the bulleted list.
Step-15: Select a data field for the value of the bulleted list. and press ok button
select one those field in bulleted list

Run your application
how to bind bulleted list in asp.net

Finally source of the code are:



<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default2.aspx.cs" Inherits="Default2" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
    
        <asp:BulletedList ID="BulletedList1" runat="server" DataSourceID="SqlDataSource1" DataTextField="Name " DataValueField="Url">
        </asp:BulletedList>
        <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:ConnectionString %>" SelectCommand="SELECT * FROM [mytab]"></asp:SqlDataSource>
    
    </div>
    </form>
</body>
</html>
Top Related Article

Monday, December 2, 2013

Data Engine for Database Developer: Introduction to SQL

SQL Server, a data engine introduced by Microsoft, lies at the core of data Management solution of an organization. It allows secure, efficient storage and Management of data. SQL database Server also provides other components and Services that support the business intelligence platform to generate reports and facilitate Data analysis used by database developer.

Every organization needs to maintain information related to employees, Customers or Business partners. Organizations build business applications either to store and manipulate the information or to generate reports. In addition, they need a platform that can be used to store and maintain these information in an efficient way. Various database management systems (DBMS) and relational database Management system (RDBMS) such as SQL Server 2005, Oracle and Sybase can be used to maintain this information.
How to install SQL Server
It is important for a database developer to identify the role of a database server in an organization, to effectively design and implement database solutions by using SQL Server, to identify its components and services. In Addition, you need to understand the basics of SQL, a language that is used to query and manage data.

Role of a Database Server

Earlier, organizations used to store the data on paper. With an increase in the usage of computers, they began building and using business applications to support the business operations.

The business applications accept data/information as input, process the data based on business requirements and provide data/information as output. For example, an application that maintains the sales details for an organization, accepts the details of the sales transaction from the users. The data is saved and an output message will display confirming that the data has been saved.

For example, the Human Resource department of an organization uses an application to manage employee’s data. The users need to add the details of new employees. The application provides an interface to enter the employee details. These details are validated for accuracy based on business rules. A business rule is defined to check that the date of joining of the new employee is less than or equal to the current date. If the data meets the requirements, it is saved in the data store.

Architectures used in Business application

Friday, October 4, 2013

How to Edit Columns in SQL Server Binding: Windows Froms

When we bind the data grid view with SQL Server database, then it will show all the columns created in the table of database. According to our previous post we have displayed all the records of table, without writing a single line of code.

Now in previous example all the columns are shown even the primary key of table. In this article we will remove those columns by some mouse clicks.

A datagridview tasks pop-up menu appears automatically, as shown in below image, click on Edit Columns link button.

How to Edit Columns in SQL Server Binding: Windows Froms


By clicking on this link button, some column names are shown in left side and on the right side there are some properties of that particular selected column.

How to Edit Columns in SQL Server Binding: Windows Froms


To remove a column, just select that and click on remove button (just below the selected columns panel), and it will be removed. We can easily change the header text of the particular column. Select a column and on the right side edit the value of Header Text.

How to Edit Columns in SQL Server Binding: Windows Froms


Perform the editing you want and at the last, click on ok button. All the settings you changed has been saved and when you run the project only three columns Code, Description and Type will be shown like:

How to Edit Columns in SQL Server Binding: Windows Froms

Wednesday, September 25, 2013

How to Retrieve Data from SQL Database: Windows Forms

In my previous post, I have created a connection object and then get all the records from the database table. What if we want to bind our datagridview without writing a single line of code? So in this article we will do something like this.


 Just drag-n-drop a datagridview on the form and name it, if you want. A datagridview tasks pop-up menu appears automatically as shown:

How to Retrieve Data From SQL Server Database and bind to DataGridView in Windows Forms

Select the Choose Data Source drop-down list and then Add Project Data Source as shown:

How to Retrieve Data From SQL Server Database and bind to DataGridView in Windows Forms

Now Data Source Configuration wizard will open, select Database as your data source. The wizard will look like:

How to Retrieve Data From SQL Server Database and bind to DataGridView in Windows Forms

By clicking on Next button, It will prompt for the database model you want to use. Select dataset, it will determines the type of data objects our application will use.

How to Retrieve Data From SQL Server Database and bind to DataGridView in Windows Forms

In the next step we have to choose our connection that is used by the application use to connect to the database.

How to Retrieve Data From SQL Server Database and bind to DataGridView in Windows Forms

Click on New Connection and it will prompt for Choose Data Source dialog box having some more options to select.

How to Retrieve Data From SQL Server Database and bind to DataGridView in Windows Forms

Select Microsoft SQL Server which is used to connect to MS SQL Server, and the data provider should be .NET Framework Data Provider for SQL Server. Add Connection dialog box will appear as shown:

How to Retrieve Data From SQL Server Database and bind to DataGridView in Windows Forms

Write the server name as given “(LocalDb)\v11.0”, and select appropriate database name from the drop down list below. I have select StockDb here. Just click on Test Connection to check our connection succeeded or not.

How to Retrieve Data From SQL Server Database and bind to DataGridView in Windows Forms

Press ok and it will show Data Source Configuration wizard again with the specified connection and also connection string.

How to Retrieve Data From SQL Server Database and bind to DataGridView in Windows Forms

Choose the table name from the tree view shown. I have select Groups table because I want to show the records of groups table. Finish now with selecting the data set name. If you will forget the dataset name, it will used the by default name.

How to Retrieve Data From SQL Server Database and bind to DataGridView in Windows Forms

It will show the datagridview binding with the columns names of groups table as shown in the above image. Now run the project and look out the records bind to the datagridview

How to Retrieve Data From SQL Server Database and bind to DataGridView in Windows Forms

As I have said above, we have not wrote a single line of code.

Thursday, September 19, 2013

How to Execute Parameterized SQL Statements: ADO.NET

As we know, SQL statements can be of simple type or may be parameterized. The parameterized query contains some parameters, which may be accepted through object of SqlParameter class. SqlParameter class is used to create the parameters used by the command object to execute the Sql queries.
Write the following code to select a record from the table groups which has a given name. The name is passed by the parameter i.e. Sql Parameter.
SqlConnection connection = new SqlConnection();
connection.ConnectionString = "Data Source= (LocalDb)\\v11.0; Initial Catalog=StockDb; Integrated Security=True";
connection.Open();
SqlCommand command = new SqlCommand("select * from Groups where code=@code", connection);
command.Parameters.AddWithValue("@code", 04);
SqlDataReader dr = command.ExecuteReader();

Look out the command object which have a variable name @code. It is the syntax of parameter used. In the next line, the parameter is added by using the function AddWithValue(). This method takes two parameter i.e. one for variable name (same as used in command object) and the second one is its value.

Now when we execute this code, a single record having code = 04 will be returned and can be accessed by data reader object dr.

We can check the rows as the same procedure as in previous post.

How to Execute SQL Statements: ADO.NET

We have learnt about ADO.NET object model. In that article we have created a SQL connection, open that connection and close that connection. To execute the SQL statements, we have to write them in between the open and close method of the above connection.

So to execute the SQL statement we have to, first create the connection, open that, write some code which will be executed and at the last execute it with ExecuteReader() method of SQLCommand class.

SqlCommand class is used to specify the Sql statement to be executed and the connection that need to be used. It can also be used to execute stored procedures. Following code will used to execute Sql statement in a command object:


SqlConnection connection = new SqlConnection();
connection.ConnectionString = "Data Source=(LocalDb)\v11.0; Initial Catalog=StockDb; Integrated Security=True";
connection.Open();
SqlCommand command = new SqlCommand("select * from Groups", connection);
SqlDataReader dr = command.ExecuteReader();

In the above code, when SqlCommand object will create, an object of SqlDataReader have been also created. And it is initialized with the function ExecuteReader(). Now all the data can be accessed one by one through dr object, one by one.

When we check the dataReader object through the breakpoint then there are some rows, as shown in following image:

Execute SQL Statement in ADO.NET


See also: Parameterized Sql Queries
© Copyright 2013 Computer Programming | All Right Reserved