Популярное

Музыка Кино и Анимация Автомобили Животные Спорт Путешествия Игры Юмор

Интересные видео

2025 Сериалы Трейлеры Новости Как сделать Видеоуроки Diy своими руками

Топ запросов

смотреть а4 schoolboy runaway турецкий сериал смотреть мультфильмы эдисон
dTub
Скачать

GridView insert update delete without using datasource controls - Part 25

Автор: kudvenkat

Загружено: 2013-03-14

Просмотров: 124483

Описание:

Link for csharp, asp.net, ado.net, dotnet basics and sql server video tutorial playlists
   / kudvenkat  

Link for text version of this video
http://csharp-video-tutorials.blogspo...

Healthy diet is very important both for the body and mind. If you like Aarvi Kitchen recipes, please support by sharing, subscribing and liking our YouTube channel. Hope you can help.
   / @aarvikitchen5572  

We discussed about inserting, updating and deleting data from gridview, using sqldatasource control in Part 23. In Part 24, we discussed about achievieng the same, using ObjectDataSource control. It is also possible to perform insert, update and delete on gridview, without using datasource controls at all, and that's what we will discuss in this video. Please watch Part 23 and Part 24, before proceeding with this video. We will be modifying the example, that we used in Part 24.

1. As we don't want to use datasource controls. Please delete "ObjectDataSource1" control from the webform.

2. Delete DataSourceID="ObjectDataSource1" from GridView1. This should remove the dependency of GridVIew1 on ObjectDataSource1 control.

3. From the code behind file, delete lbInsert_Click() event handler method.

4. In the "FooterTemplate" of "EmployeeId" TemplateField, please delete OnClick="lbInsert_Click", as we no longer have this event handler method.

5. Delete "CommandField" column from GridView1

6. Now, include a template field in the place of CommandField. This template field is used to display Edit, Update, Cancel and Delete link buttons. We don't want delete and cancel buttons to cause validation, so set CausesValidaion property of these buttons to false.

7. Copy and paste the following private method. This method binds employee data with gridview1 control.
private void BindGridViewData()
{
GridView1.DataSource = EmployeeDataAccessLayer.GetAllEmployees();
GridView1.DataBind();
}

8. Call BindGridViewData() in Page_Load() event.
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
BindGridViewData();
}
}

7. Finally generate GridView1_RowCommand() event handler method. Copy and Paste the following code.
protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
{
if (e.CommandName == "EditRow")
{
int rowIndex = ((GridViewRow)((LinkButton)e.CommandSource).NamingContainer).RowIndex;
GridView1.EditIndex = rowIndex;
BindGridViewData();
}
else if (e.CommandName == "DeleteRow")
{
EmployeeDataAccessLayer.DeleteEmployee(Convert.ToInt32(e.CommandArgument));
BindGridViewData();
}
else if (e.CommandName == "CancelUpdate")
{
GridView1.EditIndex = -1;
BindGridViewData();
}
else if (e.CommandName == "UpdateRow")
{
int rowIndex = ((GridViewRow)((LinkButton)e.CommandSource).NamingContainer).RowIndex;

int employeeId = Convert.ToInt32(e.CommandArgument);
string name = ((TextBox)GridView1.Rows[rowIndex].FindControl("TextBox1")).Text;
string gender = ((DropDownList)GridView1.Rows[rowIndex].FindControl("DropDownList1")).SelectedValue;
string city = ((TextBox)GridView1.Rows[rowIndex].FindControl("TextBox3")).Text;

EmployeeDataAccessLayer.UpdateEmployee(employeeId, name, gender, city);

GridView1.EditIndex = -1;
BindGridViewData();
}
else if (e.CommandName == "InsertRow")
{
string name = ((TextBox)GridView1.FooterRow.FindControl("txtName")).Text;
string gender = ((DropDownList)GridView1.FooterRow.FindControl("ddlGender")).SelectedValue;
string city = ((TextBox)GridView1.FooterRow.FindControl("txtCity")).Text;

EmployeeDataAccessLayer.InsertEmployee(name, gender, city);

BindGridViewData();
}
}

8. If you want to show a confirmation dialog box, before a row is deleted, include javascript confirm() function, using "OnClientClick" attribute of LinkButton "lbDelete".

GridView insert update delete without using datasource controls - Part 25

Поделиться в:

Доступные форматы для скачивания:

Скачать видео mp4

  • Информация по загрузке:

Скачать аудио mp3

Похожие видео

Displaying summary data in asp.net gridview footer - Part 26

Displaying summary data in asp.net gridview footer - Part 26

The Good Life Radio • 24/7 Live Radio | Best Relax House, Chillout, Study, Running, Gym, Happy Music

The Good Life Radio • 24/7 Live Radio | Best Relax House, Chillout, Study, Running, Gym, Happy Music

What is viewstate in asp.net - Part 3

What is viewstate in asp.net - Part 3

Cascading dropdownlist using jquery and asp net

Cascading dropdownlist using jquery and asp net

ПОСЛЕДСТВИЯ ОПЕРАЦИИ «ГРЕНЛАНДИЯ». БЕСЕДА С ВИТАЛИЙ ПОРТНИКОВ @portnikov.argumenty

ПОСЛЕДСТВИЯ ОПЕРАЦИИ «ГРЕНЛАНДИЯ». БЕСЕДА С ВИТАЛИЙ ПОРТНИКОВ @portnikov.argumenty

4 Hours Chopin for Studying, Concentration & Relaxation

4 Hours Chopin for Studying, Concentration & Relaxation

Предсказания шаманов, удары по АЭС перед Давосом, Кадыровы на грани  @BelkovskiyS #белковский

Предсказания шаманов, удары по АЭС перед Давосом, Кадыровы на грани @BelkovskiyS #белковский

Внезапно миролюбивый Путин снова на связи (English subtitles)

Внезапно миролюбивый Путин снова на связи (English subtitles)

Понимание Active Directory и групповой политики

Понимание Active Directory и групповой политики

УТРО  16.01.2026

УТРО 16.01.2026

КЛАССИЧЕСКАЯ МУЗЫКА ДЛЯ ВОССТАНОВЛЕНИЯ НЕРВНОЙ СИСТЕМЫ🌿 Нежная музыка успокаивает нервную систему 22

КЛАССИЧЕСКАЯ МУЗЫКА ДЛЯ ВОССТАНОВЛЕНИЯ НЕРВНОЙ СИСТЕМЫ🌿 Нежная музыка успокаивает нервную систему 22

Implement custom paging in an asp.net gridview without using datasource controls - Part 54

Implement custom paging in an asp.net gridview without using datasource controls - Part 54

Кадыров не переживет смерти Адама | Срочный Разбор

Кадыров не переживет смерти Адама | Срочный Разбор

Microsoft Intune: от нуля до героя

Microsoft Intune: от нуля до героя

Смертоносные тени из моря: Шайетет 13 - самый опасный спецназ Израиля

Смертоносные тени из моря: Шайетет 13 - самый опасный спецназ Израиля

Филипп Робертс: Что за чертовщина такая event loop? | JSConf EU 2014

Филипп Робертс: Что за чертовщина такая event loop? | JSConf EU 2014

ЭКСПРЕСС-КУРС PostgreSQL — изучайте PostgreSQL в 2024 году

ЭКСПРЕСС-КУРС PostgreSQL — изучайте PostgreSQL в 2024 году

Экспресс-курс RAG для начинающих

Экспресс-курс RAG для начинающих

NI в Жизни, Бизнесе и Науке | Топ Инновационных Компаний и LabVIEW | Database Tool | Insert Record

NI в Жизни, Бизнесе и Науке | Топ Инновационных Компаний и LabVIEW | Database Tool | Insert Record

Linux Command Line for Beginners

Linux Command Line for Beginners

© 2025 dtub. Все права защищены.



  • Контакты
  • О нас
  • Политика конфиденциальности



Контакты для правообладателей: infodtube@gmail.com