-----------------------------------------------------------

New Message on BDOTNET

-----------------------------------------------------------
From: Kani
Message 1 in Discussion

We are creating a Datagrid in which the columns and rows will be created 
dynamically.  First the columns will be created dynamically using the 
InstatiateIn method. Then using Add Row button, we are trying to add a row 
dynamically using the same InstatiateIn method.  PROBLEM : The problem is the 
row is getting added dynamically but the fields values are not retained.  
Viewstate is not working for the text fields which are there in the 
ItemTemplate column of the grid.
Please go through the code and let us know the solution as early as possible : 
The code is as given below:
===========================================================      public class 
DataGridTemplate : ITemplate
  {
   
   ListItemType templateType;
   string columnName;    public DataGridTemplate(ListItemType type, string 
colname)
   {
    templateType = type;
    columnName = colname;
   }    public void InstantiateIn(System.Web.UI.Control container)
   {
    container.EnableViewState = true;
    Literal lc = new Literal();
    switch(templateType)
    {
     case ListItemType.Header:
      lc.Text = "&nbsp;<BR><B>Engagement</B>";
      container.Controls.Add(lc);
      break;
     case ListItemType.Item:
      DropDownList ddl = new DropDownList();
            container.Controls.Add(ddl);
      ddl.ID = "ddlGrid" ;
            break;
     case ListItemType.EditItem:
      TextBox tb = new TextBox();
      tb.Text = "";
      container.Controls.Add(tb);
      break;
     case ListItemType.Footer:
      lc.Text = "<I>" + columnName + "</I>";
      container.Controls.Add(lc);
      break;
     
    }
    container.EnableViewState = true;
   }
  }   
===================================================  private void LoadControls()
  {
   ButtonColumn btnc3 = new ButtonColumn();
   btnc3.ButtonType = ButtonColumnType.PushButton;
   btnc3.Text = "Delete";
   btnc3.CommandName = "Delete";
   DataGrid1.Columns.Add(btnc3);
   DataGrid1.Columns[0].ItemStyle.HorizontalAlign = HorizontalAlign.Center;
   
        
   TemplateColumn tc1 = new TemplateColumn();
   tc1.HeaderTemplate = new DataGridTemplate(ListItemType.Header, "Column1");
   tc1.ItemTemplate = new DataGridTemplate(ListItemType.Item, "Column1");
   tc1.EditItemTemplate = new DataGridTemplate(ListItemType.EditItem, 
"Column1");
   tc1.FooterTemplate = new DataGridTemplate(ListItemType.Footer, "Column1");
   DataGrid1.Columns.Add(tc1);    DataGrid1.HeaderStyle.HorizontalAlign = 
HorizontalAlign.Center ;
   DataGrid1.Columns[1].ItemStyle.HorizontalAlign = HorizontalAlign.Center ;
   DataGrid2.HeaderStyle.HorizontalAlign = HorizontalAlign.Center ;            
for (int i=0;i<1;i++)
   {
     // create Template columns
    string count = i.ToString();
    TemplateColumn tcl = new TemplateColumn();     string ColumnName = "tcl" ;
    ColumnName = ColumnName + count;     tcl.HeaderTemplate = new 
DataGridTemplate2(ListItemType.Header, ColumnName);
    tcl.ItemTemplate = new DataGridTemplate2(ListItemType.Item, ColumnName);
    tcl.EditItemTemplate = new DataGridTemplate2(ListItemType.EditItem, 
ColumnName);
    tcl.FooterTemplate = new DataGridTemplate2(ListItemType.Footer, ColumnName);
    
    DataGrid2.Columns.Add(tcl);    }
  
   LoadGrid();
  } ============================================================== private void 
LoadGrid()
  {
   try
   {
    objDBUtil = new DBUtil.DBUtil("strDBConnString");
    string strQuery = "select conId,conFname from Consultant";
    ds = objDBUtil.GetDataSet(strQuery);
    dt = ds.Tables[0];    
    //dg.DataSource = intItems;
    DataGrid1.DataSource = ds;
    DataGrid2.DataSource = ds;
    Session["ds"] = ds;
    DataGrid1.DataBind();
    DataGrid2.DataBind();
   }
   catch(Exception exp)
   {
    string str = exp.Message;
   }
  }

-----------------------------------------------------------

To stop getting this e-mail, or change how often it arrives, go to your E-mail 
Settings.
http://groups.msn.com/bdotnet/_emailsettings.msnw

Need help? If you've forgotten your password, please go to Passport Member 
Services.
http://groups.msn.com/_passportredir.msnw?ppmprop=help

For other questions or feedback, go to our Contact Us page.
http://groups.msn.com/contact

If you do not want to receive future e-mail from this MSN group, or if you 
received this message by mistake, please click the "Remove" link below. On the 
pre-addressed e-mail message that opens, simply click "Send". Your e-mail 
address will be deleted from this group's mailing list.
mailto:[EMAIL PROTECTED]

Reply via email to