Click to See Complete Forum and Search --> : break issue


sweet_babylhyn
October 4th, 2010, 02:18 AM
I have a gridview which dynamically create ItemTemplate on run time. My problem is I cannot insert break point in every row. Its only working if I have two rows but when more than 2, the textbox align in 1 row only. I used literal and HtmlGenericControl but the same output. thanks in advance!



protected void buildColumns()
{
this.gvCOT.Columns.Clear();
TemplateField templateField = new TemplateField();
templateField.ItemTemplate = new GridViewTemplate(DataControlRowType.DataRow, "test");
templateField.HeaderTemplate = new GridViewTemplate(DataControlRowType.Header, "test");
templateField.ItemStyle.HorizontalAlign = HorizontalAlign.Left;
this.gvCOT.Columns.Add(templateField);

System.Data.DataTable dt = new System.Data.DataTable();
dt.Columns.Add("test", typeof(string));
dt.AcceptChanges();

System.Data.DataRow row = dt.NewRow();
row["test"] = "";
dt.Rows.Add(row);
dt.AcceptChanges();

this.gvCOT.DataSource = dt;
this.gvCOT.DataBind();
}




public class GridViewTemplate: ITemplate
{
private DataControlRowType templateType;
private string columnName;

public GridViewTemplate(DataControlRowType type, string colname)
{
templateType = type;
columnName = colname;
}

public void InstantiateIn(System.Web.UI.Control container)
{
switch (templateType)
{
case DataControlRowType.Header:
Label lbl = new Label();
lbl.Text = columnName;
container.Controls.Add(lbl);
break;
case DataControlRowType.DataRow:
//HtmlGenericControl lineBreak = new HtmlGenericControl("br");
Control c1= new LiteralControl("<br />");

TextBox txt = new TextBox();
txt.Width = 50;
txt.Text = "1";
container.Controls.Add(txt);
container.Controls.Add(c1);

txt = new TextBox();
txt.Width = 50;
txt.Text = "2";
container.Controls.Add(txt);
container.Controls.Add(c1);

txt = new TextBox();
txt.Width = 50;
txt.Text = "3";
container.Controls.Add(txt);
container.Controls.Add(c1);

break;
default:
break;
}
}

}