Home » Asp.net

Retrieve data from gridview

Hi all,

I use gridview to display the details of a bill table. its databound. and i display the values in table td. in item template.


                                                  <td width="10%" align="left">

and i have an empty textbox as the last row in the gridview display

<asp:TextBox ID="txtpayment" runat="server" ></asp:TextBox>

i need to retrieve the value entered in the textbox of each row and its corresponding Billno in the cs page

i use a button and i retrieve the data in the button click event method.

i have used several options like "foreach (GridViewRow row in grdcstomers.Rows)" and storing the gridview values in an array list

but i am unable to retrieve the cell values or the textbox values.

Please help


5 Answers Found


Answer 1


Textbox txtPay = new Textbox();
txtPay = (Textbox)txtrow.FindContorl("txtPayment")

someThing = txtPay.Text

Or if that does not work, try this...

Textbox txtPay = new Textbox();
txtPay = (Textbox)YourGridView.RowIndex(row.RowIndex).FindContorl("txtPayment")


Answer 2

No, this statement is wrong:

<td width="10%" align="left">

      <asp:TextBox id="txtBox" runat="server" Text='<%#Eval("xxx")%>'/>

After databind successfully, please use foreach, as what you say or the man said above me...



Answer 3


Currently you are writing the value from the DB directly inside a <td> tag which will be directly printed on the aspx page.

If you want to use this value elsewhere, you can add a textbox or a lable control and bind the value to its Text property.

Once done, you can use the FindControl() method of your GridView to find the label/textbox, get the value and assign it to another control/process it. 


Answer 4

Hi there thankyou all,

I used the TextBox Find Control and got the value.

But when i use Label i bind the datasource value to the text atrribute of the label as you have suggested

like Text="<%#Eval("Billno")%>"

i get the value as <%

can you help me out


Answer 5

Use this (single quote):




Hi dude,

Does any body know how to retrieve data from gridview on row selectindexchanged??



I have the following Stored Procedure: 

CREATE PROCEDURE [dbo].[GetEmployeesByCity] 

    @City NVARCHAR(15)


    SELECT *
    FROM Employees
    WHERE City = @City


I have imported this into an Entity Model, done by Function import and have the following Data Service

namespace NorthWindDB
    public class NorthwindDS : DataService<NorthwindEntities>
        // This method is called only once to initialize service-wide policies.
        public static void InitializeService(IDataServiceConfiguration config)
            config.SetEntitySetAccessRule("*", EntitySetRights.All);
            config.SetServiceOperationAccessRule("*", ServiceOperationRights.All);

        public ObjectResult<Employees> GetEmployeesByCity(string cityName)
            NorthwindEntities entities = new NorthwindEntities();
            return entities.GetEmployeesByCity(cityName);


Now if I make the following URL 

I get data back.

The question is

1. How do I call this from a Silverlight Application

For example my code for retrieving from a table is as follows;

            DataGrid myGrid = (DataGrid)this.ListWindow.Children[0];
            svc = new NorthwindEntities(new Uri("http://localhost:4143/NorthwindDS.svc", UriKind.RelativeOrAbsolute));


                myGrid.SelectionChanged += new SelectionChangedEventHandler(myGrid_SelectionChanged);
                var q = (from c in svc.Customers
                         select c) as DataServiceQuery<Customer>;

                    (ar) => myGrid.ItemsSource = q.EndExecute(ar).ToList(),

            catch (Exception ex)
                throw ex;

2. How do I can this from a windows client

Thanks in advance 



please help for,

Retrieve uploaded data through fit bit and Pulse Oxymeter device health data from MS Health Vault in code c# language.




i want xml data to store in .sdf but i dont know how to do this,..if any body knows tht answer  plz help me out,.

wht i hv done is like i conveted xml data in byte arrary and try to store in .sdf file

I am following the examples in the help file, they work fine for filtering HTTP data...but I am trying to filter for Kerberos traffic.

Specifically, the following code snippet from "Filtering Live Data and Retrieving Data Fields" works:

            ret = NmAddFilter(myFrameParserConfig, L"http.request.command == \"GET\"", &myHTTPFilterID);
            if(ret != 0)
                wprintf(L"Failed to add fitler, error 0x%X\n", ret);

            ret = NmAddField(myFrameParserConfig, L"http.request.uri", &myHTTPFieldID);
            if(ret != ERROR_SUCCESS)
                wprintf(L"Failed to add field, error 0x%X\n", ret);

And the following does not work:
            ret = NmAddFilter(myFrameParserConfig, L"TCP.Port == 0x58", &myKERBFilterID);  //tcp port 88 = kerberos
            if(ret != 0)
                wprintf(L"Failed to add fitler, error 0x%X\n", ret);

            ret = NmAddField(myFrameParserConfig, L"Ethernet.Ipv4.Tcp.TCPPayload.Kerberos.AsReq.KdcReq.PaData.PaData.PaData.PkAsRepOld.dhInfo.dhSignedData.Content.IdSignedData.Certificates.Certs.Cert.Certificate.TbsCertificate.Subject", &myKERBFieldID);
            if(ret != ERROR_SUCCESS)
                wprintf(L"Failed to add field, error 0x%X\n", ret);

What am I doing wrong?  
BTW, I got that field description using the example field iteration code and scraped from screen output of capture.  So, it appears at some level, the parser understands that field... but it appears that when filtering, my field description is not recognized by the parsing engine, is there something I need to include or change?

Thanks in advance!


I am trying to pull all of the associated data from a SharePoint list row to an InfoPath form repeating table.  I would like to select 1 unique value from the row and have the other fields auto-populate with the associated data from that row. 


SharePoint Columns and also names of InfoPath fields 1, 2, 3, 4, 5, 6, 7.

I have a dropdown that is connected to column 1 and I would like to select 1 and have it populate the rest of the fields from that row.  I am currently doing this with information and C# code from:  http://www.bizsupportonline.net/infopath2007/sharepoint-list-retrieve-value-same-row-repeating-table-infopath.htm I have also added conditional formatting to the repeating table that says if Column 1 in the repeating table doesn’t = the dropdown hide all other rows in the table so that only the row I asked for in the dropdown is visible.

Problem: I would like to be able to do math with this data I have selected/visible, currently it does not allow me to.  I would like to do a calculation like this; if 5= NO, set field 4 and field 7 to the product of 2*3. If 5=YES, set field 7 to 2*3=4+6. I may need to explain that better.

I think this http://msdn.microsoft.com/en-us/library/bb509311(office.12).aspx is trying to answer my question but I am not sure because most of the language is over my head as I have no programming experience. I just got lucky finding, copying, and pasting the code to get where I am.

I hope this makes sense to someone...





I'm trying to make a dropdown list with data available based on the users login name. Heres what I have as my SQL Query in the SQLDataSource:

SELECT Client_Name, Client_ID FROM Client WHERE (Client_Name LIKE '%@Client_Name%')

So say if the login username is "User1" but the database client name is "User1 Steel" I want the dropdownlist to pull "User1 Steel" as the display and Client_ID as the value from the dropdown list. 

I dont know how to use the session data!


using asp.net/vb.net 2005

I want to create an accordion inside a gridview with the following functionality:

The user will only see one field of the gridview initially, the ProductCategoryID.  When the page loads it will only query the ProductCategoryID and this will be the only field displayed.

Next when the user clicks on the accordion to expand it inside the gridview I would like to query the database to get all Products that are part of the ProductCategory.  I will query using the ProductCategoryID that is being displayed.

I need to do this for performance issues.  The main thing I am looking for is how to query the database once the user expands a given ProductCategoryID.

but now I think of it one thing I need to know:  when you bind an accordion to a dataset will it create one pane for each record returned?  It might be better to put the gridview inside the accordion.  I'm willing to do either, as long as it works





I dont know why my GridView.DataSource is become nothing when the Page.IsPostBack = true.What i did is bind the dataset to the GridView.DataSource when page load. Then when the button click event is trigger i need to get all the records from GridView. But when i debug and check i found that the GridView.DataSource is become nothing. Can someone tell me how should i get all records from the GridView and assign to dataset. I'm using VB.net to work on. Thanks.


Hello all,

In my GridView I have Hidden column contains ID. When User selects the rows and clicks on Delete Button( This is placed top of the Grid) Selected Rows will be deleted.

my delete button code is ...

foreach (GridViewRow dgi in Grid_Inbox.Rows){

CheckBox chkSelected = (CheckBox)dgi.FindControl("chk_Select");

if (chkSelected.Checked == true)


string strID = dgi.Cells[1].Text;

//Delete the Rows



//Binding the Grid



problem is when i am accessing through the code. getting cell value as blank. plz tell me how to get the hidden value




myString is always empty in the code below. ANy idea why?


protected void GridView1_SelectedIndexChanged(Object sender, EventArgs e)


GridViewRow row = GridView1.SelectedRow;

string myString = row.Cells[0].Text;









I have a grid view. When I click edit, the OnRowCommand fires and the row goes into edit state. Label becomes a TextBox. I then attempt to alter this value in some way and click update. This again fires the OnRowCommand event. The problem is, when I attempt to capture the new value, it instead just shows the original value.

In my grid view I have:


<asp:TemplateFieldHeaderText="Start Name">










<asp:TextBoxID="txtStartName"runat="server"Text='<%#Bind("StartName") %>'></asp:TextBox>





In my code behinde i have


textBox = (TextBox)row.Cells[4].FindControl("txtStartName");

Any help would be very appreciated.





I know there are a number of posts along this topic, but everything I find seems to not have a final solution or else I'm just not getting what the solution is.  I have a simple GridView with a ButtonField and a BoundField.  I'm having the same problem most of the other posts seem to have; I can retrieve the BoundField value easy enough in the  RowCommand subroutine, but I can't figure out how to get the value of the ButtonField.  Here is the code I'm trying to use:




     <asp:ButtonFieldButtonType="Link"CommandName="btnName"DataTextField="NAME" />




PrivateSub gvTest_RowCommand(ByVal sender AsObject, ByVal e As System.Web.UI.WebControls.GridViewCommandEventArgs) Handles gvTest.RowCommand

  Dim sAddr AsString = gvTest.Rows(e.CommandArgument).Cells(0).Text

  Dim sName AsString = gvTest.Rows(e.CommandArgument).Cells(1).Text



sAddr is being set to the correct address value, but sName is set to an empty string no matter what I try.  The GridView HTML all works correctly, including showing the names from my bound data table on the button text.  Could someone please show me a code snippet I can use to retrieve the ButtonField text value?  As you can see, I'm using VB so a VB response would be greatly appreciated.

Thanks for your help! 



couple of things:

(1) in a gridview there is the CommandField where you can use 'select' which simply highlights a row in the grid data. upon clicking this, can i use javascript to show a pop up message?

(2) upon clicking the CommandField 'select' can i retrieve the row id? if not then if i convert one of my column (type bit) and convert to checkbox, upon checking the checkbox, can i retrieve the row id?

i need the row id to process elsewhere




I am exporting data from gridview to excel file.
My problem is that for all the string which contain "+", the rest of data begining from it is missing in excel file.

For example: PWE-WER+78, when exported it will become PWE-WER.

Below is my code.


                    Response.Buffer = True
                    Response.AddHeader("Content-Disposition", "attachment;filename=" & "ExportedExcel.xls")
                    Response.ContentType = "application/vnd.ms-excel"
                    Response.Charset = ""
                    lobjStringWriter = New StringWriter
                    lobjHtmlWriter = New HtmlTextWriter(lobjStringWriter)

I  have search through online but no solution.
Does anyone has idea on this?

SQL Server 2000

What is the eayest and shortest way to save an SQL SELECT output in to a local XML file and retrieve it back as table rows by another program ?
Thanks, adh


I need to get information from a table on a secure web page, I have already dealt with getting to the url and inserting the credentials, however this is where I'm stuck.  From searching the web for the past 2 weeks i ran across several forums where they suggested using the HTMLAgilityPack which is what I used to get the path to where the table resides on the web page, however I have no clue as to how to implement it.  I figure once I figure out how to get the data I would import it into a datagrid and then into a sql table.

Anyway here is the tag path that the HTMLAgiltyPack gave me :/html[1]/body[1]/table[1]/tbody[1]/tr[4]/td[1]/table[1]/tbody[1]/tr[2]/td[3]/table[1]/tbody[1]/tr[1]/td[1]/table[1]/tbody[1]/tr[2]/td[2].  This was just to get to the table holding the information I need.  How do I input this into my code.  I'm using VB.Net however a C# example would work also.

Any Assistance would be greatly welcomed


I posted this question on microsoft.public.platformsdk.security, but since the newsgroups are getting phased out, I thought I would repost here:

On Windows 7, I'd like to be able to store a piece of data that can only be retrieved if the user proves who they are using their fingerprint. I'd like the authentication to be required even if they are already logged in to their account.

I know that the DPAPI would allow me to store a piece of data that requires a typed password to decrypt (using the PromptStruct). And I know that the WBF (Windows Biometric Framework) provides a way to verify/identify a user based on a fingerprint swipe. However, I can't figure out a way to use these two APIs in conjunction so that DPAPI can take a fingerprint instead of a typed password as input.

Any ideas? Perhaps I need to take a completely different approach...

Thanks in advance,


Hi All,

I have a scenrio where i need to move node to another node.  Let me give in details.

I need to build xml from sql server table as follows,






















In the above Xml i need to check <containergroup>1</containergroup> under Reports/REport, if exist i have to take the whole tags under reports and insert in a new second <group></Group> under <group></group>, hide <containergroup>1</containergroup> from xml.

Similarly if <containergroup>0</containergroup> i should not change.  But if ONLY <containergroup>0</containergroup> is presend and no other containergroup, then i need to insert in a new <group> </group> hardcoded values...

Please let me know how to achieve.


Krithikan A



Hi There,

I wrote my first Odata consumer application. The service is running fine. I can retrieve data directly from web ui. But I could not get data through my silverlight application. The code is as follows.

private void MainPage_Loaded(object sender, RoutedEventArgs e)


WarehouseModelContainer _context =newWarehouseModelContainer(newUri("http://serviceuri"));

DataServiceCollection<Task> _tasks= newDataServiceCollection<Task>();

_tasks.LoadCompleted += DataLoaded;

var query = ((from a in _context.Tasks select a).Take(10));



privatevoid DataLoaded(object sender, LoadCompletedEventArgs e) { //do something }


Debugging it, I found that in the Dataloaded function, the _tasks has no records.

What is wrong with my code?



<< Previous      Next >>

Microsoft   |   Windows   |   Visual Studio   |   Sharepoint   |   Azure