Problem reading value form Gridview template field.

G

Guest

Hi,
I have the foll template field

<asp:TemplateField HeaderText="Quantity" ItemStyle-HorizontalAlign="center">
<ItemTemplate>
<%# Eval("quantity") %>
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox ID="txtQty" runat="server" Width="29"
Height="13" Text='<%# Eval("quantity") %>'></asp:TextBox>
</EditItemTemplate>
</asp:TemplateField>

I am able to read the EditItem by this

..Quantity = CType(r.Cells(e.RowIndex).FindControl("txtQty"), TextBox).Text

but when I try to read from the ItemTemplate like this

..Quantity = r.Cells(9).Text

I get Null or empty value. Please advice.

Thanks
 
B

bpd

Hi,
I have the foll template field

<asp:TemplateField HeaderText="Quantity" ItemStyle-HorizontalAlign="center">
<ItemTemplate>
<%# Eval("quantity") %>
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox ID="txtQty" runat="server" Width="29"
Height="13" Text='<%# Eval("quantity") %>'></asp:TextBox>
</EditItemTemplate>
</asp:TemplateField>

I am able to read the EditItem by this

.Quantity = CType(r.Cells(e.RowIndex).FindControl("txtQty"), TextBox).Text

but when I try to read from the ItemTemplate like this

.Quantity = r.Cells(9).Text

I get Null or empty value. Please advice.

Thanks

I believe you need Quantity = r.Cells(9).Controls(1).Text
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,772
Messages
2,569,588
Members
45,099
Latest member
AmbrosePri
Top