473,765 Members | 1,994 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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...th en why do we need to re-bind the web control to the datasource.

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

DataGrid1.EditI temIndex = e.Item.ItemInde x
DataGrid1.DataB ind()

What am I missing here?

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

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

rather than in

datagrid.DataBi nd()

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

DataGrid1.EditI temIndex = e.Item.ItemInde x
DataGrid1.DataB ind()

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

HTH

Elton Wang
el********@hotm ail.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...t hen why do we need to re-bind the web control to the datasource.
DataGrid1.Edit ItemIndex = -1
DataGrid1.Data Bind()
Similarily we use databind to re-bind the datagrid, when the user clicks therow he wants to edit.

DataGrid1.Edit ItemIndex = e.Item.ItemInde x
DataGrid1.Data Bind()

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
2269
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 help with the navigation through a datagrid. The control handles all the paging issues and on the webform I do all the DataBinding. My problem is that at the end of code of an on-click event for a link button on my user control...
4
2321
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 help with the navigation through a datagrid. The control handles all the paging issues and on the webform I do all the DataBinding. My problem is that at the end of code of an on-click event for a link button on my user control...
3
3828
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 cell of the current row, I could force this row to be saved in the datasource. help plz
9
4608
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 consistant. Thanks, Tom.
2
1772
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
1383
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 Databind line. When I removed all the columns and dg is left with <columns></columns>, I don't get an error. If there's any column in the collection no matter what column it is, the error comes back. All the datafield names correspond to the column...
2
1256
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
2055
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: If I do the SQL query and the DataGrid.DataBind() in the Page_Load(), and then I do it AGAIN inside the SortCommand function I set up, everyhting works fine. But that seems inefficient because it means that the DataGrid.DataBind() gets called...
0
1284
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 follows and is fired on OnInit string grid = "<asp:DataGrid ID=\"grid2\" runat=\"server \"><Columns><asp:TemplateColumn><ItemTemplate><asp:LinkButton ID= \"link1\" runat=\"server\"><%# DataBinder.Eval(Container.DataItem,
0
9566
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
1
9946
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9832
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8830
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7371
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6646
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5272
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
3921
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 we have to send another system
2
3530
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.