Results 1 to 7 of 7

Thread: TextBoxes in datagrid

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Mar 2004
    Posts
    24

    TextBoxes in datagrid

    Hi guys,
    Can anyone help me in this. I want to put textboxes in the datagrid in asp.net
    It should function like flexgrid. I am stuck up in this
    thank u

  2. #2
    Frenzied Member Magiaus's Avatar
    Join Date
    Mar 2002
    Location
    swamp land
    Posts
    1,267

    Re: TextBoxes in datagrid

    Create a TextBox in code and add it to the cell of the row you want. Cell.Controls.Add()

    I know that's a just scraping the surface but it's not to complex it's just a matter of when you want there to be a TextBox and I'm not sure when that is. I haven't used a flexgrid in years and years.
    Magiaus

    If I helped give me some points.

  3. #3
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170

    Re: TextBoxes in datagrid

    Another way: Make it an <asp:TemplateColumn> and place the textbox in there.

  4. #4

    Thread Starter
    Junior Member
    Join Date
    Mar 2004
    Posts
    24

    Re: TextBoxes in datagrid

    Thanks Guys

    But can u explain me in detail

  5. #5
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170

    Re: TextBoxes in datagrid

    Magiaus will explain his version, and I'm guessing it'll probably be easier than mine, but to each his own.

    Code:
    <asp:TemplateColumn ItemStyle-Wrap="False">
    						<HeaderStyle Width="10%"></HeaderStyle>
    						<ItemTemplate>
    							
    							<asp:TextBox id="txtToDateTime" MaxLength="255" runat="server" CssClass="cssTextbox" Width="110px"
    								BackColor="Transparent" Wrap="False"></asp:TextBox>&nbsp;&nbsp;
    						</ItemTemplate>
    					</asp:TemplateColumn>
    In the codebehind, under the DataGrid's ItemDataBound event,

    PHP Code:
    //This is C#
    TextBox txtTDT = (TextBox)e.Item.FindControl("txtToDateTime");

    //And then I populate it like so:
    txtTDT.Text DateTime.Parse(dsResultSet.Tables[0].Rows[i]["ToDateTime"].ToString()).ToString("MM/dd/yyyy HH:mm"); 

  6. #6
    Frenzied Member Magiaus's Avatar
    Join Date
    Mar 2002
    Location
    swamp land
    Posts
    1,267

    Re: TextBoxes in datagrid

    Well, basicly the two are almost the same. I would probably add the textbox in the ItemCreated event.

    PHP Code:
    private void DataGrid1_ItemCreated(object senderSystem.Web.UI.WebControls.DataGridItemEventArgs e)
    {
        
    System.Web.UI.WebControls.TextBox t = new System.Web.UI.WebControls.TextBox();
        
    t.ID "txt" e.Item.ItemIndex.ToString();
        
    //Now you would want to clear out any cell text and put it in the textbox.
        
    t.Text e.Item.Cells[0].Text;
        
    e.Item.Cells[0].Text "";
        
    //add an event wire-up here +=
        //t.TextChanged += ....
        
    e.Item.Cells[0].Controls.Add(t);
    }

    private 
    void DataGrid1_UpdateCommand(object sourceSystem.Web.UI.WebControls.DataGridCommandEventArgs e)
    {
        
    System.Web.UI.WebControls.TextBox t;
        
    = (System.Web.UI.WebControls.TextBox)e.Item.FindControl("txt" e.Item.ItemIndex.ToString()); 

        
    //save changes

    If you need a box in every cell you could take on some cell info to the ID. And loop through the cells for each item adding boxes.
    Magiaus

    If I helped give me some points.

  7. #7
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170

    Re: TextBoxes in datagrid

    While you can use either method, keep in mind that my method can keep you warm at night and walk your dogs for you.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width