DataGrid textbox

Discussion in 'ASP .Net' started by Maziar Aflatoun, Jun 12, 2004.

  1. 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.
     
    Maziar Aflatoun, Jun 12, 2004
    #1
    1. Advertising

  2. Maziar Aflatoun

    Teemu Keiski Guest

    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" <> wrote in message
    news:2IDyc.270$...
    > 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.
    >
    >
     
    Teemu Keiski, Jun 12, 2004
    #2
    1. Advertising

  3. 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.
    >
    >
    >
     
    =?Utf-8?B?cmFuZ2FuaA==?=, Jun 12, 2004
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. S. Justin Gengo
    Replies:
    0
    Views:
    578
    S. Justin Gengo
    Jul 16, 2003
  2. Hazzard
    Replies:
    2
    Views:
    586
    Yan-Hong Huang[MSFT]
    Jul 23, 2003
  3. Natty Gur
    Replies:
    0
    Views:
    496
    Natty Gur
    Jul 22, 2003
  4. matthew schouppe
    Replies:
    3
    Views:
    2,383
    Scott Allen
    Apr 30, 2004
  5. matthew schouppe

    DataGrid ItemStyle is a textbox and doesn't update the datagrid datasource

    matthew schouppe, Apr 29, 2004, in forum: ASP .Net Datagrid Control
    Replies:
    3
    Views:
    218
    Scott Allen
    Apr 30, 2004
Loading...

Share This Page