Display Data in GridView Without Using Code

Abstract

Every organization is always hunting for quality resources for project development. So for every interview round there is always a technical round to check for technical knowledge. Sometimes the logical question is asked. One of my friends asked one question. So I thought to write articles and share with all of you.

Problem statement

Without writing one line of code do the following.

Bind a student_ id to dropdown list. Display the details of the student in a GridView depending on the student _id of the dropdownlist in ASP.Net.

Note: the problem statement was very complicated but I simplified it.

Solution

So many times programmers are confused about how to develop without one line of code. Some are saying it is impossible to do without writing one line of code. Some only know how to bind data to a control using data sources. But they don't know how to check depending on a condition.

It is possible in ASP.NET.

Let's learn step-by-step.

Step 1

Open Visual Studio. Click on File -> New -> Website.

Website

Step 2

Select the language as Visual C# and template as ASP.NET web Forms site. Provide an appropriate name and location and click on OK.

web Forms site

Step 3

Drag and drop a Dropdownlist onto the page. Check that the Autopostback is enabled. For binding the data source select choose a data source.

Dropdownlist

Step 4

Select ”New DataSource” form the first dropdownlist.

New DataSource

Step 5

Choose the data source that you want to bind to. I chose SQL data source. Click on OK.

data source

Step 6

If you have already bound to the database, choose something in the dropdownlist otherwise click on New Connection. I chose New Connection.

bind database

Step 7

Enter the server name and choose authentication. If using Server Authentication then enter a User Name and Password. Also select database. And for confirmation of the Test connection, click on Test Connection. If the connection is accessed it displays a message, click on OK. Again, click on OK to close the windows.

authentication

Step 8

Now it displays the connection string. Click on Next.

display connection string

Step 9

Check the connection string and save it in the configuration file. And click on Next.

configuration

Step 10

Here in the dropdownlist we are only bound to a Student_id so check the student_id and click on Next.

click on Next

Step 11

Click on Test Query to display the available student _id in the database. Click on Finish.

Test Query

Step 12

Finally, it displays all the details that you bound to the dropdownllist. Click on OK.

displays all the detail

Now the student_id is bound to the dropdownlist.

Next we need to display records depending on the dropdownlist value in the GridView.

Step 13

Drag and drop one GridView. Select “New data Souce”.

gridview

Step 14

Select SQL Datsource Type and click on OK.

Datsource

Step 15

Now directly choose the connection string then click on Next.

connection string

Step 16

Click on Next.

display all record

Step 17

Check * to display all the records. Now we need to display records depending on the condition. Click on where.

Select column

Step 18

Select the student_id column, the operator is = and now here is the main thing. Here we can bind the source. You can bind the source on that in various ways. Here we will bind the control. Choose the control ID as dropdownlist. Click on Add and then the OK button.

click on Test Query

Step 19

Now click on Test Query. You will be rompted for the Parameter, for example I enter the Student id parameter as 1 and click OK.

enter Parameter

Step 20

Now the record is displayed depending on the parameter that was passed. Now click on Finish.

display record

Step 21

Now run the webpage and check. It displays the details of the student depending on the student id of the dropdownlist.

display details

student id

I hope you like my article.

If you have any such kind of problem statement then frankly drop mail to me at [email protected]. I am happy to help you and provide a better solution.

For more article visit my blog.

Your feedback and suggestion is always welcomed by me.


Similar Articles