.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

Return value from SqlDataSource in GridView ?

Posted By:      Posted Date: August 29, 2010    Points: 0   Category :ASP.Net
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?

View Complete Post

More Related Resource Links

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.

Binding xml data (which is return from Url) to gridview


I have used Yahoo BOSS API for internal search. This API return string and i want to bind it with gridview. How can i achieve this following is the code

string AppId = "sRP_q9bV34HI_zNyuahPFBGnf1SHyBaIKCtvEjB89EuiNJI6fcfSwAFbwAFSsCV_";
//string Query = "site:way2k.com engineering colleges in pune";
string Query = "colleges in pune"; int NumResults = 10;
     int NumResults = 10;
System.Net.WebClient webClient = new System.Net.WebClient(); request = string.Format( "http://boss.yahooapis.com/ysearch/web/v1/{1}?appid={0}&format=xml&results={2}", AppId, Query, NumResults); byte[] response = webClient.DownloadData(request); string responseXML = System.Text.UTF8Encoding.UTF8.GetString(response); return responseXML;

this code returns result in xml format, how can i bind this XML to gridview so that it looks like search result

How to return back to a specific page in a gridview list?

Hello,  I have a gridview with paging. So for instance, I'm on say the page number 10, and I open the form details on a specific record_id (link). After I update/submit the form, it returns to page number 10. But, if I go to another page, for instance page 5, and submit the form, it returns to page 10. I've tried some things, for instance history.back(), but it returns to the first page I went to, in this case page number 10 (or whatever the first page I go to). Hopefully this code helps to understand what I'm asking: <asp:GridView DataKeyNames="Referral ID" ID="gvList" runat="server" CellPadding="4"     ForeColor="#333333" GridLines="None" OnRowCommand="gvList_RowCommand"     OnRowDataBound="gvList_RowDataBound" OnRowDeleted="gvList_RowDeleted"     OnRowDeleting="gvList_RowDeleting" AllowPaging="True" PageSize="20"     AutoGenerateColumns="False" OnPageIndexChanging="gvList_PageIndexChanging"    OnRowCreated="OnRowCreated" AllowSorting="True" OnSorting="OnSort"> protected void gvList_PageIndexChanging(object sender, GridViewPageEventArgs e)        {   &nb

row.Cells[4].Text return nothing in GridView ?

I have a GridView in my page : <asp:GridView ID="GridView1" runat="server" AllowPaging="True" BackColor="White" AutoGenerateColumns="False" EmptyDataText="No data available." BorderColor="#DEDFDE" BorderStyle="None" BorderWidth="1px" CellPadding="4" Width="729px" ForeColor="Black" GridLines="Vertical" OnSelectedIndexChanged="GridView1_SelectedIndexChanged"> <RowStyle BackColor="#F7F7DE" /> <Columns> <asp:TemplateField HeaderText="TransactionKey" SortExpression="TransactionKey"> <EditItemTemplate> <asp:TextBox ID="TextBoxGridViewTransactionKey" runat="server" Text='<%# Bind("TextBoxTransactionKey") %>'></asp:TextBox> </EditItemTemplate> <ItemTemplate> <asp:Label ID="LabelGridViewTransactionKey" runat="server" Text='<%# Bind("TextBoxTransactionKey") %>'></asp:Label> </ItemTemplate> <HeaderStyle Font-Size="14px" /> <ItemStyle Font-Size="12px" /> </asp:TemplateField> <asp:TemplateField He

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

GridView bound to SqlDataSource = 2 tier ?


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 ?

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 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

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

SqlCeException (0x80004005) Trying to load a page with GridView and a SqlDataSource connecting to SQ



On my local machine everything works fine.

I have uploaded my website to an ISP and while trying to open a page with GridView and a SqlDataSource connecting to SQL CE 4 sdf file following exception gets generated.

Server Error in '/' Application.

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.Data.SqlServerCe.SqlCeException: [ 1884,d:\DZHosts\LocalUser\gasasso\www.gasasso.somee.com\App_Data\gasasso.sdf,SeCreateFile ]

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:

Inplace Edit in GridView

In this article I am presenting a different way to look at EditItemTemplate, using which user navigation for editing is reduced and . it looks very different (see screeen shots) then regular implementation of GridView.

GridView Confirmation Box Using JQuery BlockUI in asp.net

JQuery is the most popular JavaScript library. One of the main reasons for its fame is the plugin architecture. Anyone can create a separate library that leverage the JQuery library. In this article we are going to look at the BlockUI library which is used to block the user screen while performing a task.

Textbox Editable GridView in ASP.NET

This article describes how I made a fully editable gridview in C# using ASP.NET 2. The idea is that the GridView looks and works like an Excel spreadsheet. You see all the cells in the table, and you can edit any of the cells you like, and they are automatically updated (i.e. saved to the database). This is very often how people expect data tables to work in web pages, and I've often seen people clicking in vain on un-editable gridview cells, somehow expecting to edit them, and not understanding that they need to click an Edit button at the end of the row.

Adding Dynamic Rows in ASP.NET GridView Control with TextBoxes and with Delete functionality

In my previous examples, I have demonstrated on how to add dynamic rows in GridView control with TextBoxes and how to save the values into the database. Now, seems that most of the developers are asking if how to add a delete functionality with it. So in this example, I'm going to show on how to delete a certain row in the dynamic GridView with TextBoxes.
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