473,473 Members | 1,523 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

GridView, dataTable and two way binding

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[i].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
Jul 18 '06 #1
0 2669

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Steven Blair | last post by:
Hi, I am using a GridView and have it bound to a ObjectDataSource. After the binding has been successfull, I need to access the original datasource (which I guess is a DataSet) to display some...
3
by: Richard Carpenter | last post by:
I have a simple winform with a customers combobox, a "get orders" button and an orders grid. Due to other requirements, I have implemented the form to allow the user to select a customer from the...
4
by: Tomasz Jastrzebski | last post by:
Hello Everyone, I have a GridView control bound to a plain DataTable object. AutoGenerateEditButton is set to true, Edit button gets displayed, and RowEditing event fires as expected.
0
by: ack95 | last post by:
Simply question How can I DataBind() a DataViewManager to a GridView in ASP.NET? Question in Detail We have a DataSet with relational DataTables (total of 5). We are generating emails with...
4
by: Yin99 | last post by:
I have a Gridview binding to a DataTable source. I'd like to set the column with of the second column. I cannot do this apparently because when AutoGenerateColumns=true, they do not appear in the...
3
by: RobertTheProgrammer | last post by:
Hi folks, I've got another problem. Basically, I'm trying to use a nested GridView, however the nexted GridView displays no values (even though in debug I'm getting valid values into my DataSet. ...
2
by: DC | last post by:
Hi, I am using a GridView to present data in a DataTable, which I store only in ViewState and when the user hits the "OK" button the rows in the DataTable will be used to execute transactions. ...
4
by: Craig Buchanan | last post by:
I dynamically add data-bound templates to a gridview in my ascx control. while this works correctly when the gridview is databound to the datatable, i'm having issues on postback. i would like...
0
by: cmrhema | last post by:
Hi, I have a gridview problem while binding more than two gridviews. I am giving a sample scenario of what I have done so far I have two tables First table: Department , having columns...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.