Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > DataGrid textbox

Reply
Thread Tools

DataGrid textbox

 
 
Maziar Aflatoun
Guest
Posts: n/a
 
      06-12-2004
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.


 
Reply With Quote
 
 
 
 
Teemu Keiski
Guest
Posts: n/a
 
      06-12-2004
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.

--
Teemu Keiski
MCP, Microsoft MVP (ASP.NET), AspInsiders member
ASP.NET Forum Moderator, AspAlliance Columnist
http://blogs.aspadvice.com/joteke




"Maziar Aflatoun" <(E-Mail Removed)> wrote in message
news:2IDyc.270$(E-Mail Removed). rogers.com...
> 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.
>
>



 
Reply With Quote
 
 
 
 
=?Utf-8?B?cmFuZ2FuaA==?=
Guest
Posts: n/a
 
      06-12-2004
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.


"Maziar Aflatoun" wrote:

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

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
DataGrid ItemStyle is a textbox and doesn't update the datagrid datasource matthew schouppe ASP .Net Datagrid Control 3 04-30-2004 03:02 PM
DataGrid ItemStyle is a textbox and doesn't update the datagrid datasource matthew schouppe ASP .Net 3 04-30-2004 03:02 PM
runat="server"....a simple html textbox or a webform server textbox...that is the question. Hazzard ASP .Net 2 07-23-2003 07:32 AM
Re: runat="server"....a simple html textbox or a webform server textbox...that is the question. Natty Gur ASP .Net 0 07-22-2003 03:57 AM
Re: VERY STRANGE BUG? Adding a textbox control causes other textbox control to fail??? S. Justin Gengo ASP .Net 0 07-16-2003 06:51 PM



Advertisments