W
witek
I am lost.
There is a dataTable with data which I want to dispaly in GridView.
dataTable is not connected to any database. Just dataTable with data.
There is a class wich is used as column template
//-------------------------------------------------------------------------------------------------------
public class TextBoxTemplate :ITemplate
{
DataControlRowType m_rowType;
string m_dataField;
public TextBoxTemplate (DataControlRowType rowType, string dataField)
{
m_rowType = rowType;
m_dataField = dataField;
}
void ITemplate.InstantiateIn (System.Web.UI.Control container)
{
TextBox txt = new TextBox ();
txt.DataBinding += new EventHandler (txt_DataBinding);
container.Controls.Add (txt);
}
void txt_DataBinding (object sender, EventArgs e)
{
TextBox txt = (TextBox)sender;
GridViewRow row = (GridViewRow)txt.NamingContainer;
txt.Text = DataBinder.Eval
(row.DataItem, this.m_dataField).ToString ();
}
}
//-------------------------------------------------------------------------------------------------------
GridView is build dynamically.
//-------------------------------------------------------------------------------------------------------
for (int i = 0; i < dt.Columns.Count; i++)
{
TemplateField tf = new TemplateField ();
tf.ItemTemplate = new TextBoxTemplate
(DataControlRowType.DataRow, dt.Columns.ColumnName);
gv.Columns.Add (tf);
}
//-------------------------------------------------------------------------------------------------------
and finally bound.
//-------------------------------------------------------------------------------------------------------
gv.DataSource = dataTable;
gv.DataBind ();
//-------------------------------------------------------------------------------------------------------
and now here is a question.
How to acomplish two way bindig, to have data back in dataTable (for
example after clicking button on a page)?
I can't find any documentation how to do that.
I found something about IBindableTemplate and ExtractValues but I don't
know how to use that.
for some resons I can't use DataSourceID, I can't build DataSourceObject
class.
The only thing which I can is having gridview and datatable.
Thanks
There is a dataTable with data which I want to dispaly in GridView.
dataTable is not connected to any database. Just dataTable with data.
There is a class wich is used as column template
//-------------------------------------------------------------------------------------------------------
public class TextBoxTemplate :ITemplate
{
DataControlRowType m_rowType;
string m_dataField;
public TextBoxTemplate (DataControlRowType rowType, string dataField)
{
m_rowType = rowType;
m_dataField = dataField;
}
void ITemplate.InstantiateIn (System.Web.UI.Control container)
{
TextBox txt = new TextBox ();
txt.DataBinding += new EventHandler (txt_DataBinding);
container.Controls.Add (txt);
}
void txt_DataBinding (object sender, EventArgs e)
{
TextBox txt = (TextBox)sender;
GridViewRow row = (GridViewRow)txt.NamingContainer;
txt.Text = DataBinder.Eval
(row.DataItem, this.m_dataField).ToString ();
}
}
//-------------------------------------------------------------------------------------------------------
GridView is build dynamically.
//-------------------------------------------------------------------------------------------------------
for (int i = 0; i < dt.Columns.Count; i++)
{
TemplateField tf = new TemplateField ();
tf.ItemTemplate = new TextBoxTemplate
(DataControlRowType.DataRow, dt.Columns.ColumnName);
gv.Columns.Add (tf);
}
//-------------------------------------------------------------------------------------------------------
and finally bound.
//-------------------------------------------------------------------------------------------------------
gv.DataSource = dataTable;
gv.DataBind ();
//-------------------------------------------------------------------------------------------------------
and now here is a question.
How to acomplish two way bindig, to have data back in dataTable (for
example after clicking button on a page)?
I can't find any documentation how to do that.
I found something about IBindableTemplate and ExtractValues but I don't
know how to use that.
for some resons I can't use DataSourceID, I can't build DataSourceObject
class.
The only thing which I can is having gridview and datatable.
Thanks