Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > DataGrid ItemStyle is a textbox and doesn't update the datagrid datasource

Reply
Thread Tools

DataGrid ItemStyle is a textbox and doesn't update the datagrid datasource

 
 
matthew schouppe
Guest
Posts: n/a
 
      04-29-2004
I have a datagrid with two columns, the first a normal bound column,
the second is a template column created from a bound column. For the
ItemTemplate of the Template Column, I removed the label and replaced
it with a textbox. Displaying the data from the datasource is not a
problem, however when I change the data in the textbox and click on an
update button (the thought being that multiple rows will have been
changed and I can simply use the update command of the DataAdapter),
the underlying datasource (a DataSet) has HasChanges()=false. What am
I not doing to cause the DataSet to be updated when the user changes
the text in the textbox?

Thanks.

private DataSet ds = new DataSet();
private SqlDataAdapter sda = new SqlDataAdapter("SELECT orderid,
shipname FROM orders", new
SqlConnection("Server=(local)\\NetSDK;Integrated Security=true;Initial
Catalog=Northwind"));

private void Page_Load(object sender, System.EventArgs e)
{
if (!IsPostBack)
{
sda.Fill(ds, "orders");
DataGrid1.DataSource = ds.Tables["orders"];
DataGrid1.DataBind();
}
}

Private void Button1_Click(object sender, System.EventArgs e)
{
if (ds.HasChanges()) <- ALWAYS FALSE
{
ds.AcceptChanges();
sda.Update(ds);
sda.Fill(ds, "orders");
DataGrid1.DataSource = ds;
DataGrid1.DataBind();
}
}
 
Reply With Quote
 
 
 
 
Michael Tkachev
Guest
Posts: n/a
 
      04-30-2004
Private void Button1_Click(object sender, System.EventArgs e)
{
foreach(DataGridItem i in DataGrid1.Items)
{
TextBox tb = ((i.Cells[1].Controls[1]));
... Your code;
}
}


Michael.

"matthew schouppe" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed) om...
> I have a datagrid with two columns, the first a normal bound column,
> the second is a template column created from a bound column. For the
> ItemTemplate of the Template Column, I removed the label and replaced
> it with a textbox. Displaying the data from the datasource is not a
> problem, however when I change the data in the textbox and click on an
> update button (the thought being that multiple rows will have been
> changed and I can simply use the update command of the DataAdapter),
> the underlying datasource (a DataSet) has HasChanges()=false. What am
> I not doing to cause the DataSet to be updated when the user changes
> the text in the textbox?
>
> Thanks.
>
> private DataSet ds = new DataSet();
> private SqlDataAdapter sda = new SqlDataAdapter("SELECT orderid,
> shipname FROM orders", new
> SqlConnection("Server=(local)\\NetSDK;Integrated Security=true;Initial
> Catalog=Northwind"));
>
> private void Page_Load(object sender, System.EventArgs e)
> {
> if (!IsPostBack)
> {
> sda.Fill(ds, "orders");
> DataGrid1.DataSource = ds.Tables["orders"];
> DataGrid1.DataBind();
> }
> }
>
> Private void Button1_Click(object sender, System.EventArgs e)
> {
> if (ds.HasChanges()) <- ALWAYS FALSE
> {
> ds.AcceptChanges();
> sda.Update(ds);
> sda.Fill(ds, "orders");
> DataGrid1.DataSource = ds;
> DataGrid1.DataBind();
> }
> }



 
Reply With Quote
 
 
 
 
matthew schouppe
Guest
Posts: n/a
 
      04-30-2004
I don't understand the reference to '...Your code;'. How is the
ds.HasChanges() affected by the foreach statement?

I thought that at some point I saw an article that had an example of
this where the entire grid was saved using sqlDataAdapter.Update(ds),
I just don't know how to get my textbox to register a change to the
dataset.

Matthew

"Michael Tkachev" <(E-Mail Removed)> wrote in message news:<(E-Mail Removed)>...
> Private void Button1_Click(object sender, System.EventArgs e)
> {
> foreach(DataGridItem i in DataGrid1.Items)
> {
> TextBox tb = ((i.Cells[1].Controls[1]));
> ... Your code;
> }
> }
>
>
> Michael.

 
Reply With Quote
 
Scott Allen
Guest
Posts: n/a
 
      04-30-2004

Matthew:

The data binding in ASP.NET is "one way". In order to get values from
the controls on the page back into your data source, you need to write
code to move the values. Michael was demonstrating some code to
iterate through the grid to pull out all the values in the TextBox
controls. Using this loop you could then put the text into your
populated DataSet, than use the Update method to push the values into
the database.

HTH,

--
Scott
http://www.OdeToCode.com

On 30 Apr 2004 05:33:05 -0700, http://www.velocityreviews.com/forums/(E-Mail Removed) (matthew schouppe)
wrote:

>I don't understand the reference to '...Your code;'. How is the
>ds.HasChanges() affected by the foreach statement?
>
>I thought that at some point I saw an article that had an example of
>this where the entire grid was saved using sqlDataAdapter.Update(ds),
>I just don't know how to get my textbox to register a change to the
>dataset.
>
>Matthew
>
>"Michael Tkachev" <(E-Mail Removed)> wrote in message news:<(E-Mail Removed)>...
>> Private void Button1_Click(object sender, System.EventArgs e)
>> {
>> foreach(DataGridItem i in DataGrid1.Items)
>> {
>> TextBox tb = ((i.Cells[1].Controls[1]));
>> ... Your code;
>> }
>> }
>>
>>
>> Michael.


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Question about DataGrid ItemStyle leodippolito@gmail.com ASP .Net 1 04-29-2005 02:34 PM
<ItemStyle Wrap="False" ForeColor="#000066"></ItemStyle> Diego ASP .Net 0 11-12-2004 02:10 PM
ItemStyle from DataGrid Paul King ASP .Net 4 07-21-2004 12:16 PM
DataGrid ItemStyle is a textbox and doesn't update the datagrid datasource matthew schouppe ASP .Net Datagrid Control 3 04-30-2004 03:02 PM
ItemStyle ForeColor on a datagrid Clive ASP .Net 0 07-14-2003 11:28 AM



Advertisments