Displaying a TextBox in a datagrid

  • Thread starter Thread starter Maziar Aflatoun
  • Start date Start date
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.
 
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
 
Back
Top