Displaying a TextBox in a datagrid

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.
 
C

Cliff Harris

Well, the short answer is to create a templated column:

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

However, you may want to look into making the datagrid into an editable
datagrid.. (however, this only allows eiditng only row at a time).

HTH,
-Cliff
 

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

Top