Read data from Datagrid webcontrol

B

Bas Jaburg

Hello,

I have populated a datagrid on my aspx page with data from the
database. The datagrid also has TemplateColumn with a textbox to enter
the quantity in. If I submit, the data in that column seems to be
empty. It's not the Postback thing, I already checked that. All the
other data is there, but the freshly entered data is not.

The grid looks something like this:

<asp:datagrid id="dgProducts" runat="server">
<Columns>
<asp:BoundColumn DataField="ID" HeaderText="ID"></asp:BoundColumn>
<asp:TemplateColumn HeaderText="Quantity">
<ItemTemplate>
<asp:TextBox Runat="server" />
</ItemTemplate>
</asp:TemplateColumn>
</Columns>
</asp:datagrid>

(so this one has two columns)

If I try to read it using:

foreach (DataGridItem item in dgProducts.Items)
{
Response.Write (item.Cells[1].Text);
}

it shows nothing!

What am i doing wrong?

Help greatly appreciated.

Regards

Bas Jaburg
 
R

Ravikanth[MVP]

Hi

Please check the following msdn article
http://msdn.microsoft.com/msdnmag/issues/01/06/cutting/cut
ting0106.asp

Ravikanth[MVP]

-----Original Message-----
Hello,

I have populated a datagrid on my aspx page with data from the
database. The datagrid also has TemplateColumn with a textbox to enter
the quantity in. If I submit, the data in that column seems to be
empty. It's not the Postback thing, I already checked that. All the
other data is there, but the freshly entered data is not.

The grid looks something like this:

<asp:datagrid id="dgProducts" runat="server">
<Columns>
<asp:BoundColumn DataField="ID"
HeaderText="ID"> said:
<asp:TemplateColumn HeaderText="Quantity">
<ItemTemplate>
<asp:TextBox Runat="server" />
</ItemTemplate>
</asp:TemplateColumn>
</Columns>
</asp:datagrid>

(so this one has two columns)

If I try to read it using:

foreach (DataGridItem item in dgProducts.Items)
{
Response.Write (item.Cells[1].Text);
}

it shows nothing!

What am i doing wrong?

Help greatly appreciated.

Regards

Bas Jaburg
.
 

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

No members online now.

Forum statistics

Threads
474,077
Messages
2,570,566
Members
47,202
Latest member
misc.

Latest Threads

Top