.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month
Gaurav Pal
Post New Web Links

GridView bound to SqlDataSource = 2 tier ?

Posted By:      Posted Date: September 19, 2010    Points: 0   Category :ASP.Net

Hi guys,

I've got two questions about n-tier architecture.

I have an aspx page with 2 controls on it - a GridView bound to a SqlDataSource control.
Am I correct in thinking this is 2-tier ?

If I were to replace the SqlDataSource with an ObjectDataSource, and make the database connections/calls/queries via a class in the App_Code folder, this would be 3-tier, right ?

View Complete Post

More Related Resource Links

Format Generic List Bound to Gridview


I have a generic list of a custom type. The custom type has a string and double.

I'm binding the list to a gridview and it outputs everything fine.

I'm trying to format the double column into a currency format. It is in a template field as I'm calculating a running total. I pass the value to a function that returns a double and adds the current value to a running total which I will show in the footer.

The format is not changing to currency as expected when using String.Format("{0:c}", GetTotal(Convert.ToDouble(Eval("Amount"))))

Any ideas on what might be going on and how to fix this?


Binding GridView with SqlDataSource at runtime?


Hi, I want to create a generic page which contains a gridview and sqldatasource. I want to put these two controls on .aspx (C#) page but bind them at runtime. It should have selectcommand, updatecommand, deletecommand and insertcommand. Stored procedures are created for that. Help is needed to make it. Please post some link or code. Regards, ap.

Gridview Update outside of SqlDatasource


Is it possible to use a SQLDataSource to populate a gridview but not use the SQLDataSource for Updating?

I wanted to add the update code in the Gridview_RowUpdating event since it is a complex update I need to do.

I get this message when i click the update button

Updating is not supported by data source 'SqlDataSource1' unless UpdateCommand is specified.

dropdownlist bound to sqldatasource adds items instead of replacing on change



I have a series of dropdownlists on webform in ASP 4.0. The first drop down is filled upon load, and then when a user selects a value from that list, it populates the second dropdown. To accomplish this, I have a SQLdatasource with a parametersource of the first drop-down list control. This works great, except when a user changes their selection from the first drop down. It performs the query, but then adds the list of items to the ones that were already there from the previous selection, instead of replacing it with the new data. Here is the code:

 <asp:DropDownList ID="ddlMajor" runat="server" DataMember="DefaultView" 
      DataSourceID="SqlDataSource1" DataTextField="majortext" 
      DataValueField="majorkey" AppendDataBoundItems="True" AutoPostBack="True">
         <asp:ListItem Value="0">Select Major</asp:ListItem>
<asp:DropDownList ID="ddlReq" runat="server" DataMember="DefaultView" 
      DataSourceID="SqlDataSource2" DataTextField="req" DataValueField="admreqkey" 
            AppendDataBoundItems="True" AutoPostBack="True">
                <asp:ListItem Value="0">Sel

Return value from SqlDataSource in GridView ?

Hi, everyone. I have textbox for searching a Names in My database. I return the information from the Select Statement in  GridView, but i want to know the number of affecter rows. How to do that?

Gridview (bound by ObjectDataSource) Sorting - VB.NET

Hello.. I have a gridview being data bound by an objectdatasource which points to a BLL/DAL.  I have paging and sorting enabled within the gridview. I have the fields configured in the look/fell I want from a templatefield.  This templatefield has the sort expression (date) I want things to be sorted by. All this works as it should and I have no issues with it. But, the issue is that when I click on the header to sort asc/desc by date, I have to click on it twice for it switch to descending order.  E.g.  I hit the webpage and it lists all the information in the gridview, sorted by date, ascending order.  If I want to sort by descending order, I have to click the date header twice in order for the gridview to sort the information in descending order; the clicks cause a post-back and the whole screen is refreshed. Any ideas why this may be occurring?  Thanks.. -Jeff  

Textbox -> value -> gridview -> Sqldatasource?

Hi guys. I have textbox that searches for first or last name. Result show in gridview. But when add value in text box and push my button Find nothing happen. Here code: aspx:   ........ <asp:GridView runat="server" AllowPaging="True"                   AutoGenerateColumns="False" DataKeyNames="MobileNum"                   DataSourceID="SqlDataSource5" style="font-family: Verdana"                          onselectedindexchanged="GridView1_SelectedIndexChanged">         <Columns>                         <asp:BoundField DataField="FNAME" HeaderText="FNAME" SortExpression="FNAME" />             <asp:BoundField DataField="LNAME" HeaderText="LNAME" SortExpression="LNAME" />          &nb

SQLdatasource + gridview + mysql




I have a sqldatasource and a gridview. I work with a mysql 3.51 database.

My problem is :

When I try tu update a record through the update command of the gridview, it doesn't work.  Here is my code :


asp:SqlDataSource ID="SQL_Panier" runat=server ConnectionString="<%$ ConnectionStrings:Connection to NI %>" ProviderName="<%$ ConnectionStrings:Connection to NI.ProviderName %>" SelectCommand="selectcommand"

UpdateCommand="Update Panier SET qtt=@qtt,commentaires=@commentaires WHERE email=?"

GridView - putting TemplateField fields in between data bound fields


Here is my problem.  I have a GridView, and I want Column1 to be equal to datatable data (filled by a SqlDataAdapter).  Then I have two other fields by the SqlDataAdapter (first name, last name), and I want to have those two fields combined to form Column2.  I have a TemplateField for my GridView that combines the first name and last name with Eval()'s, but the GridView places this combined field TemplateField and puts it as the first column.

How can I do this so that TemplateField can go in between fields that are databound?  Thanks in advance. :)

Gridview Sorting with SqlDataSource



I had a previous post (found here for reference: http://forums.asp.net/p/1573740/3954537.aspx#3954537) Where I was wanting to hide/assign gridviews and datasource dynamically to reduce the page load time. I now have a user requesting that one of those Gridviews be sortable. I have already gone through and added the sort Expression to each column that is created in the code behind. 

I also added a Gridview Sorting Handler

Protected Sub billingGridview_Sorting(ByVal sender As Object, ByVal e As GridViewSortEventArgs) Handles billingGridView.Sorting

But, when I rebind the data, how to I fill in the sort direction and sort Field? The datasource gets its information from a Stored Proc that does not have an Order By (parameter) in it. The websites I have been reading say to use a datatable or dataview and send the sort field and direction to the query. If I dont do all this in the code behind and allow sorting, the gridview is able to handle sorting itself. Is there any way to do this from the code behind? Or am I going to have to rework this with a query that contains a parameter for the sort direction and field?



gridview.rowcommand + sqldatasource.delete()


I have gridview+sqldatasource. In gridview i have button DELETE. But i want on click this button for some rows execute DELETE command other rows UPDATE. I did:

protected void GridMain_RowDataBound(object sender, GridViewRowEventArgs e)
  if (e.Row.RowType == DataControlRowType.DataRow)
     if (DataBinder.Eval(e.Row.DataItem, "DelFlag").ToString() == "True")
               btnDelete.CommandName = "Delete";
               btnDelete.CommandName = "DeleteVirtual";

protected void GridMain_RowCommand(object sender, GridViewCommandEventArgs e)
        if (e.CommandName == "Delete")
           sourceMain.DeleteCommand = "DELETE FROM [Main] WHERE 
        else if (e.CommandName == "DeleteVirtual")
            sourceMain.DeleteCommand = "UPDATE [Main] SET DelFlag = 'True' WHERE  
@index - DeleteParametrs in sqldatasource. But DELETE works and DELETEVIRTUAL doesn't. Then i insert sourceMain.Delete() in rowcommand after sourceMain.DeleteCommand ... But it's doesn't help m

How to Format Data inside a Bound Column of Gridview?



I have a bound column.

<asp:BoundField DataField="WorkPreference"  HeaderText="WorkPreference"
                    <HeaderStyle HorizontalAlign="Left" />

dr["WorkPreference"] = sa.WorkPreference ( This is how I bind the data  to a DataRow)

The example of the data which gets bound to this column is like the following:

Communications and Marketing Officers; Environmental Assessors; Geologists and Geosciences; Geospatial/Spatial Information Officers;

What I want is that the data should be presented to the user like the following:

Communications and Marketing Officers

Environmental Assessors

Geologists and Geosciences

Geospatial/Spatial Information Officers

In short: I basicaly want to put a break where there is a colon and then bind the data to the gridview.

It looks like simple but if you can let me know. Thanks.

please help me in creating gridview using three tier archi - i have done the coding but need more im


i am a fresher, and i am laering asp.net by myself using internet tutorials,

i am creating a website using three tier logic, i have created the sign in page with 5 controls, firstname, lastname,userid,pasword,con password.

and its working nicely using the three tier,

the same i need to perform the edit and delete section in grid view, i have tried so many times but its creating me some error, i am here posting the codel please help me to recover it

data access layer code for delete oepration

public int delete( int Userid)

        SqlConnection con = new SqlConnection("Constr");


        SqlCommand cmd = new SqlCommand("three_delete",con);

        cmd.CommandType = CommandType.StoredProcedure;




How to INSERT GridView data into another table (besides the one it is bound to)??


Hi All,

I have a tricky situation that I just cannot seem to figure out.  I'm using ASP.NET 4.0.  I have two databases (let's call them Northwind and MyDatabase for simplicity).  I cannot modify the data in Northwind, but once I save a copy to MyDatabase, I can change it.

I have a GridView that shows all the tests associated with a patient.  I first populate the GridView, retrieving all the tests in Northwind.Test that are associated to a PatientID.  On a button click event, I need to:

  1. Create a new Patient record in MyDatabase.Patient (I've got this part done already).
  2. Use that newly created PatientID and INSERT all of the rows from the GridView into MyDatabase.Test.  I have the PatientID available, I just don't know how to retrieve the data from the GridView.
  3. (Ideally) I would like to then be able to load that patient record in the future from MyDatabase and be able to UPDATE the tests in the GridView to MyDatabase.Test.

I can load the tests into the GridView no problem.  But I have no idea how I would save that data to a different datasource.  Any ideas?  Should I even be using a GridView, or something else?

-Thanks in advance-

Oracle Error when Selecting from Gridview that is bound to another Gridview



I've been working on a webform to pull data from an oracle database v10. I can create a gridview1 with Selection enabled and it will populate with data without a problem. However when I create a second gridview and bind with a control to the first gridview, I get the following error at runtime when I click on one of the Selects.

Exception Details: Oracle.DataAccess.Client.OracleException: ORA-00936: missing expression

Source Error:

An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.

Stack Trace:

[OracleException (0x80004005): ORA-00936: missing expression]
Oracle.DataAccess.Client.OracleException.HandleErrorHelper(Int32 errCode, OracleConnection conn, IntPtr opsErrCtx, OpoSqlValCtx* pOpoSqlValCtx, Object src, String procedure, Boolean bCheck) +1440

GridView - table v/s SqlDataSource ?


Hi all,

I have a gridview which i need to populate from a products database, where a user can click on a certain

product (row) and gets directed to a new page with that product ID (where he will see the product details

and so on..)

while this seems easy if i bind the gridview to a SQL Datasource, i face few problems:

1- I need to trim the product descrption and only display the first 30 characters ; some products descrption

is much more than 30 characters and i dont want to display all of it in the gridview ..

2- there is a date/time field in my sql query, which appears in the gridview as "10/21/2010 12:00:00 AM". I

don't want to display the time stamp, but only the date. any idea how?

3- if there are no data to display , the gridview header (product name, product description, entry date,

etc..) will disappear and thus the user will be confused..

As a workaround, I'm thinking of capturing the date in a Datatable, after having manipulated it as required

above, and them running a databind on the gridview, which is feasible but has its own challenges:

1- how do u display a URL with the product ID as a variable?

I'm guessing the first method is better, but I couldn't figure it out...

GridView, BoundField, SqlDataSource and DeleteParameters


Hello All,

I I have a GridView attached to a SqlDataSource and all is working well.  I also have and edit and delete icon attached to each record in the GridView, and again, all is working well.

My problem is when I add a BoundField named 'statusCode', the delete stored procedure fails with:

"Procedure or function 'up_delReference' expects parameter '@statusCode', which was not supplied."

When I remove the BoundField named 'statusCode' from the GridView list, the delete works fine.  I need to show the status in the GridView as the user can chose to see Avtive, Inavtive or Both records and they need to see the status when in Both.

Here is the Code:

<asp:GridView ID="GridViewList" runat="server" DataSourceID="SqlDataSourceList" DataKeyNames="refID" >
		<asp:TemplateField HeaderText="Action">
				<asp:ImageButton ID="ImageButtonEditDetail" runat="server" SkinID="IconEdit" CommandName="Edit" ToolTip="Edit Record" />
				<asp:ImageButton ID="ImageButtonDelete" runat="server" SkinID="IconDelete"  CommandName="Delete" ToolTip="Delete Record" OnClientClick
ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  Silverlight  Others  All   

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend