DataGrid textbox

M

Maziar Aflatoun

Hi everyone,

I have this DataGrid that I bind to a DataTable. However, instead of
displaying the column 'Qty', I like to place it in a textbox and display the
value of Qty as the default value for the TextBox. Any suggestions?

<asp:datagrid id="DGShoppingCart" runat="server" Width="650"
AutoGenerateColumns="False">
<Columns>
<asp:BoundColumn DataField="ProductName" HeaderText="Product"
HeaderStyle-Font-Bold="True" HeaderStyle-CssClass="normtext"
ItemStyle-CssClass="normtext"></asp:BoundColumn>
<asp:BoundColumn DataField="Qty" HeaderText="Quantity"
HeaderStyle-Font-Bold="True" HeaderStyle-CssClass="normtext"
ItemStyle-CssClass="normtext"></asp:BoundColumn>
<asp:ButtonColumn ButtonType="PushButton" CommandName="Delete"
Text="Delete" ItemStyle-HorizontalAlign="Center"></asp:ButtonColumn>
</Columns>
</asp:datagrid>

Thank you
Maz.
 
T

Teemu Keiski

Hi,

use TemplateColumn.

<asp:TemplateColumn>
<ItemTemplate>
<asp:TextBox ID="txtBox" runat="server"
Text='<%#DataBinder.Eval(Container.DataItem,"Qty")%>' />
</ItemTemplate>
</asp:TemplateColumn>

Note single quotes with text property and I also types this top of my head
so check the syntax. :) You probably want also set column headings and
styles for this one too.
 
G

Guest

Dear Maziar,

You can use the TemplateColumn to do the same:-

<asp:datagrid id="DGShoppingCart" runat="server" AutoGenerateColumns="False" Width="650">

<Columns>

<asp:TemplateColumn>

<ItemTemplate>

<%# (DataBinder.Eval(Container.DataItem, "ProductName" ).ToString()) %>

<asp:TextBox ID="txtQty" Text='<%# (DataBinder.Eval(Container.DataItem, "Qty" ).ToString())%>' Runat="Server" />

</ItemTemplate>

</asp:TemplateColumn>

</Columns>

</asp:datagrid>

hope it helps.






This will fetch the Qty from the database and assign it to the textbox.
 

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
473,769
Messages
2,569,578
Members
45,052
Latest member
LucyCarper

Latest Threads

Top