http://www.youtube.com/user/kudvenkat...
Link for text version of this video
http://csharp-video-tutorials.blogspo...
In this video we will discuss about editing and updating data in gridview control using objectdatasource control
We will be using tblEmployee table for this demo. SQL script to create and populate this table with sample data is available in Part 13 of asp.net gridview tutorial.
Create an asp.net web application. Drag and drop a objectdatasource control and a gridview control on webform1.aspx.
Steps to update a row in gridview using objectdatasource control.
1. Create EmployeeDataAccessLayer class
2. Create Employee business object in EmployeeDataAccessLayer.cs file
3. Add a static method to select all employees in EmployeeDataAccessLayer class
4. Add a static method to update employee record using EmployeeId, in EmployeeDataAccessLayer class
5. Configure objectdatasource and gridview control.
Now let us look at the steps in detail.
Step 1: Create EmployeeDataAccessLayer class
Right click on the web application project and add a class file with name EmployeeDataAccessLayer.cs
Step 2: Create Employee business object in EmployeeDataAccessLayer.cs file
public class Employee
{ public int EmployeeId { get; set; } public string Name { get; set; } public string Gender { get; set; } public string City { get; set; }
}
Step 3: Add a static method to select all employees in EmployeeDataAccessLayer class
Step 4: Add a static method to update employee record in EmployeeDataAccessLayer class
public static void UpdateEmployee(int EmployeeId, string Name, string Gender, string City)
{ string CS = ConfigurationManager.ConnectionStrings["DBCS"].ConnectionString; using (SqlConnection con = new SqlConnection(CS)) { string updateQuery = "Update tblEmployee SET Name = @Name, " + "Gender = @Gender, City = @City WHERE EmployeeId = @EmployeeId "; SqlCommand cmd = new SqlCommand(updateQuery, con); SqlParameter paramEmployeeId = new SqlParameter("@EmployeeId", EmployeeId); cmd.Parameters.Add(paramEmployeeId); SqlParameter paramName = new SqlParameter("@Name", Name); cmd.Parameters.Add(paramName); SqlParameter paramGender = new SqlParameter("@Gender", Gender); cmd.Parameters.Add(paramGender); SqlParameter paramCity = new SqlParameter("@City", City); cmd.Parameters.Add(paramCity); con.Open(); cmd.ExecuteNonQuery(); }
}
Step 5: Configure objectdatasource and gridview control.
Compile the project. If the project is not compiled, EmployeeDataAccessLayer class may not show up in the wizard when configuring objectdatasource control.
1. Right click on "ObjectDataSource1" control and select "Show Smart Tag"
2. Now click on "Configure Data Source" link
3. Select "EmployeeDataAccessLayer" class from "Choose your business object dropdownlist" and click next
4. On "Define Data Methods" screen, select "GetAllEmployees" method
5. Now click on "UPDATE" tab and select "UpdateEmployee()" method and click Finish
Now, associate "ObjectDataSource1" with "GridView1" and make sure you select "Enable Editing" check box, in "GridView Tasks" pane.
Run the application and click "Edit" button. Notice that "EmployeeId" is also editable. This column is the primary key column and should not be allowed to change. If you don't want a specific column to be editable in gridview, set the column's "ReadOnly" attribute to "true". Once we set "EmployeeId" bound column's "ReadOnly" attribute to "true", the row is not updated. This is because, EmployeeId is passed as ZERO. To correct this issue, set GridView1 control's DataKeyNames="EmployeeId". After these 2 changes, the gridview's EDIT and UPDATE functionality should work as expected.
asp.net core docker Editing and updating data in gridview using objectdatasource control - Part 18 | |
70 Likes | 70 Dislikes |
39,378 views views | 524K followers |
Education | Upload TimePublished on 9 Mar 2013 |
Related keywords
update mysql,wcf vs web api,ado.net core,sql server management studio,webkinz,webadvisor,craigslist nj,gridview datasource,wcf one piece,asp.net core 3,ajax players,weber grill parts,webtoon,tutorials by hugo,csharp corner,mvc design pattern,asp.net machine account,servers for minecraft,asp.net core dependency injection,ado.net tutorial,update csgo,services angular,ajax ontario,update angular cli,asp.net mvc tutorial,updating whatsapp,asp.net cos'è,csharp assembly,tutorialspoint python,sql join,services briefcase,asp.net core web api,ajax jquery,wccftech,craigslist ny,gridview flutter,asp.net zero,csharp foreach,server memes,sql date format,services online,chase,updating driving licence photo,update select,serverless architecture,server resume,wcf c#,server books,gridview rowcommand,tutorialspoint javascript,mvcc connect,ado.net mysql,services technologies gps,ajax deadpool,server jobs,cvs,updating tax credits,website,mvc tutorial,costco hours,wcf service application,tutorialspoint spring,serverless,wcf soap,wcf cat,cool math games,wcf test client,updating kitchen cabinets,services & training hse colombia sas,servicestack,citibank,asp.net core identity,sql union,ajax parking,sql database,asp.net core logging,updates were rejected because the tip of your current branch is behind,gridview devexpress c#,mvconnect,cunyfirst,asp.net guida,wcf nba,csharp download,wcfi foundation,csharp online,wcf authentication,tutorials near me,http://asp.net,server 2019,chernobyl,ado.net descargar,web of dreams,serverminer,gridview pagination,ajax cleaner,ado.net visual studio 2019,webassign,ado.net vs entity framework,ado.net visual studio 2017,gridview height,csharp list,sql like,updating chrome,asp.net mvc,asp.net core tutorial,sqlite,gridview c#,wcfm,ajax roster,mvc architecture,http://ado.net,update node,asp.net core mvc,ajax soccer,server hosting,update inner join,update viajes,updating mac os,update postgresql,wcfi,updated,ajax dish soap,capital one,server rack,tutorialspoint html,csharp interface,updating bios,craigslist,webroot,tutorialspoint reactjs,ajax request,wcf dragon ball,asp.net core 2.2,updating windows 10,tutorialspoint python 3,sql developer,webster,services transmission company sas,update windows 10,sql group by,gridviewrow,asp.net core signalr,services manager,mvc framework,ajax paving,mvc near me,update traduccion,tutorialspoint spring boot,mvc map,csharp online compiler,update chrome,update from,asp.net download,sql between,ado.net c# pdf,services tag dell,wcf 2019 nba,update oracle,csharp switch,ado.net ventajas y desventajas,csharpstar,wcf tutorial,tutorialspoint,ajax meaning,csharp-video-tutorials.blogspot,tutorials dojo,central park 5,csharp string format,ado.net c#,asp.net core github,gridview android example,updating icloud settings,server status,ajax fc,server jobs nyc,asp.net core swagger,sql formatter,credit karma,services group,gridview css,gridview yii2,server error in '/' application,services windows,asp.net core 3.0,sql injection,gridview asp.net,tutorialspoint c#,wcf ria services,updating dbs,calculator,ado.net entity data model,sql insert,tutorialspoint tableau,services google play apk,sqlyog,asp.net core 3 release date,sql server,server job description,tutorials by a,update bios,servicenow,webcam,mvc hours,updating driving licence,webmd symptom,csharp array,csharp enum,ajax call,asp.net core 2. guida completa per lo sviluppatore,gridview c# asp.net,asp.net core,updating tomtom,server pro,updating driving licence address,server status ffxiv,cheap flights,webcrims,asp.net core hosting,services sas,update java,update npm,tutorialspoint java,tutorialspoint java compiler,updating raspberry pi,webmd,csharp to json,college football,ado.net dataset,csharp dictionary,cnn,website builder,tutorialspoint sql,asp.net web api,server side rendering,weber grills,sql server 2017,tutorialspoint spark,mvc nj,ado.net oracle,asp.net core download,csharp to vb.net,gridview column width,webster bank,webstaurant,updating drivers,tutorialsystems,ajax post,services fms publish announcement,gridview devexpress,services.msc no abre,ajax jersey,csharp operator,asp.net core razor pages,server duties,asp.net core environment variables,csharp random,updating driver's license,century 21,services consultores,services consulting,gridview hide column,mvcsd,services.msc,mvcsc,ado.net pdf,asp.net core configuration,ajax marvel,updating play support libraries,sql update,asp.net tutorial,mvc medical,ado.net entity data model visual studio 2019,wcfs international curriculum,mvc2,ado.net entity data model visual studio 2017,chase online,update sql,wcf api,costco,update ubuntu,server jobs near me,webex,gridview bootstrap 4,sql meaning,sql tutorial,sql commands,ado.net entity framework,ajax tavern,tutorialsteacher,ajax javascript,services desk,ajax greek,csharp tutorial,mvc pattern,ado.net sql server,ado.net connection,asp.net identity,gridview android,mvcu,gridview bootstrap,asp.net core middleware,updating esta,gridview xamarin forms,wcf web service,updating homebrew stuck,mvc webadvisor,web store,mvcc,webmail,mvci,mvctc,updating passport,
Không có nhận xét nào:
Đăng nhận xét