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




<< Previous      Next >>

Microsoft   |   Windows   |   Visual Studio   |   Sharepoint   |   Azure