473,387 Members | 1,535 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Why databind is required while editing datagrid?

I was going through an article on datagrid control in ASP.NET and found the
use of databind a bit confusing.
So the default behavior in a editable datagrid row is to show a Update and a
Cancel Button when a user wants to edit the datagrid.
What I found confusing was the use of databinding when this cancel button is
pressed. When we are pressing the Cancel button we are not changing the
datasource...then why do we need to re-bind the web control to the datasource.

DataGrid1.EditItemIndex = -1
DataGrid1.DataBind()
Similarily we use databind to re-bind the datagrid, when the user clicks the
row he wants to edit.

DataGrid1.EditItemIndex = e.Item.ItemIndex
DataGrid1.DataBind()

What am I missing here?

Regards,
-Aayush
Nov 19 '05 #1
1 1506
Hi Aayush,

Binding a datagrid's underlying data source happens in
datagrid.DataSource = dataObject

rather than in

datagrid.DataBind()

The datagrid.DataBind() is only process of datagrid. For
example, when in Edit event it sets

DataGrid1.EditItemIndex = e.Item.ItemIndex
DataGrid1.DataBind()

After processing, the selected row becomes eatable row
(with editable textboxes and Update, Cancel buttons).

HTH

Elton Wang
el********@hotmail.com
-----Original Message-----
I was going through an article on datagrid control in ASP.NET and found theuse of databind a bit confusing.
So the default behavior in a editable datagrid row is to show a Update and aCancel Button when a user wants to edit the datagrid.
What I found confusing was the use of databinding when this cancel button ispressed. When we are pressing the Cancel button we are not changing thedatasource...then why do we need to re-bind the web control to the datasource.
DataGrid1.EditItemIndex = -1
DataGrid1.DataBind()
Similarily we use databind to re-bind the datagrid, when the user clicks therow he wants to edit.

DataGrid1.EditItemIndex = e.Item.ItemIndex
DataGrid1.DataBind()

What am I missing here?

Regards,
-Aayush
.

Nov 19 '05 #2

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

Similar topics

2
by: Stephen | last post by:
Hey everyone. I was wondering if someone could help me with a small problem. I have designed a user control and I would have inserted it on a aspz page (WebForm1). The User control is being used to...
4
by: Stephen | last post by:
Hey everyone. I was wondering if someone could help me with a small problem. I have designed a user control and I would have inserted it on a aspz page (WebForm1). The User control is being used to...
3
by: Islamegy | last post by:
When i press btn_save all changed rows in my grid get saved except the last editing row... I want my btn_Save to end editing in the datagrid.. so if user didn't press "enter" after editing last...
9
by: tshad | last post by:
Is there a way to use your own image in place of the automatic one that ASP uses when doing editing in your DataGrid pages? We already have a style of button we are using and would like to be...
2
by: Jim Bancroft | last post by:
Hi everyone, I have a DropDownList I populate as outlined below. This is from my code-behind file: private void Page_Load(object sender, System.EventArgs e) { BindMyData(); DataBind(); }
0
by: Karim | last post by:
I have a datagrid with a collection of columns and the datagrid is populated as in the code below. The value of test = 3 rows which is correct. However I get an exception when the code hits the...
2
by: Jimmy | last post by:
Hi all I want to databind a dropdownlist in a datagrid: private void Page_Load(object sender, System.EventArgs e) { // Put user code to initialize the page here
1
by: Alex Maghen | last post by:
I have a DataGrid on my ASPX and I'm confused about the interaction with the page based on whether the page is just loading or is being reloaded with a call to the SortCommand of the DataGrid: ...
0
by: Dave | last post by:
Hi, I have a very simple page where i am using Page.ParseControl to create a datagrid control. When i try to run the DataBind method i get various errors. The code for the datagrid is as...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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...

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.