|
-
Jan 27th, 2005, 11:31 AM
#1
Thread Starter
Junior Member
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
-
Jan 27th, 2005, 11:58 AM
#2
Frenzied Member
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.
-
Jan 28th, 2005, 12:19 AM
#3
Re: TextBoxes in datagrid
Another way: Make it an <asp:TemplateColumn> and place the textbox in there.
-
Jan 28th, 2005, 05:14 AM
#4
Thread Starter
Junior Member
Re: TextBoxes in datagrid
Thanks Guys
But can u explain me in detail
-
Jan 28th, 2005, 06:01 AM
#5
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>
</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");
-
Jan 28th, 2005, 10:13 AM
#6
Frenzied Member
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 sender, System.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 source, System.Web.UI.WebControls.DataGridCommandEventArgs e)
{
System.Web.UI.WebControls.TextBox t;
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.
-
Jan 29th, 2005, 09:53 AM
#7
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|