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
Printable View
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
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.
Another way: Make it an <asp:TemplateColumn> and place the textbox in there.
Thanks Guys
But can u explain me in detail
Magiaus will explain his version, and I'm guessing it'll probably be easier than mine, but to each his own.
In the codebehind, under the DataGrid's ItemDataBound event,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>
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");
Well, basicly the two are almost the same. I would probably add the textbox in the ItemCreated event.
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.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
}
While you can use either method, keep in mind that my method can keep you warm at night and walk your dogs for you. :afrog: