Dynamic Textbox in Datagrid 
Author Message
 Dynamic Textbox in Datagrid

Hi,

You can look at ItemCreated event of the DataGrid web control. When you
dynamically create a datagrid, you can hook the ItemCreated event. In the
event handlder, you can access the DataGridItem and dynamically add
controls.

Here is some code snippet just for your reference:

private void Page_Load(object sender, System.EventArgs e)
                {

                        if(!this.IsPostBack)
                        {
                                DataGrid DataGrid1 = new DataGrid();
                                DataGrid1.ItemCreated += new
DataGridItemEventHandler(DataGrid1_ItemCreated);
                                PanelTest.Controls.Add(DataGrid1);
                                DataGrid1.DataSource = CreateDataSource();
                                DataGrid1.DataBind();
                        }
                }

                ICollection CreateDataSource()
                {
                        DataTable dt = new DataTable();
                        DataRow dr;

                        dt.Columns.Add(new DataColumn("IntegerValue", typeof(Int32)));
                        dt.Columns.Add(new DataColumn("StringValue", typeof(string)));
                        dt.Columns.Add(new DataColumn("CurrencyValue", typeof(double)));

                        for (int i = 0; i < 10; i++)
                        {
                                dr = dt.NewRow();

                                dr[0] = i;
                                dr[1] = "Item " + i.ToString();
                                dr[2] = 1.23 * (i+1);

                                dt.Rows.Add(dr);
                        }

                        DataView dv = new DataView(dt);
                        return dv;
                }

                void DataGrid1_ItemCreated(Object sender, DataGridItemEventArgs e)
                {
                        DataGridItem dgi = e.Item;
                        TableCell cell = new TableCell();
                        TextBox txt = new TextBox();
                        txt.Text = "Hello";
                        cell.Controls.Add(txt);
                        dgi.Cells.Add(cell);
                }

http://www.*-*-*.com/

Hope it helps.

This posting is provided "AS IS" with no warranties, and confers no rights.

Regards,

Bill Cheng
Microsoft Support Engineer
--------------------
| Content-Class: urn:content-classes:message


| Subject: Dynamic Textbox in Datagrid
| Date: Fri, 9 Aug 2002 17:08:46 -0700
| Lines: 7

| MIME-Version: 1.0
| Content-Type: text/plain;
|       charset="iso-8859-1"
| Content-Transfer-Encoding: 7bit
| X-Newsreader: Microsoft CDO for Windows 2000
| X-MimeOLE: Produced By Microsoft MimeOLE V5.50.4910.0300
| Thread-Index: AcJAAhht2BPrXpJoRG+Mby9Gg/h0Mg==
| Newsgroups: microsoft.public.dotnet.languages.vb
| NNTP-Posting-Host: TKMSFTNGXA05 10.201.232.164
| Path: cpmsftngxa08!tkmsftngxs01!cpmsftngxa07
| Xref: cpmsftngxa08 microsoft.public.dotnet.languages.vb:59162
| X-Tomcat-NG: microsoft.public.dotnet.languages.vb
|
| Hello All, I'm dynamically creating Datagrids in a
| webform.  Inside of my datagrid I need to dynamically
| create a textbox.  I believe I need to use a template
| column, but am having trouble w/ the syntax.
|
| Thanks in advance,
| J.
|



Sat, 29 Jan 2005 10:27:24 GMT  
 
 [ 1 post ] 

 Relevant Pages 

1. datagrids and textboxes - rowchanges reflected in textbox

2. Need some help with DataGrids (DataGrid-->DataGrid, DataGrid-->Dataset, DataGrid-->XML)

3. dynamic textbox controls with text changed ??

4. DataGrid with dynamic CheckBox

5. dynamic textbox controls with text changed ??

6. dynamic textboxes..

7. TextBox Size Dynamic

8. change text in a dynamic textbox

9. Dynamic DataGrid Template Columns using ascx

10. vb.net datagrid dynamic array and navigation

11. Dynamic Datagrid

12. Datagrid/Data Report and dynamic recordsets

 

 
Powered by phpBB® Forum Software