Click here to Skip to main content
15,886,873 members

deleting rows in the gridview

abdul samathu asked:

Open original thread
I've created a Dictionary like

C#
Dictionary<department,bool> dict= new Dictionary<department,bool>();


here Department is a class and I have `DepartmentId,Name and Code` for the departments. And in the `bool` am sending whether the person is `HOD` or not.

Am adding the records to this Dictionary like

C#
dict.Add(department,chkHOD.checked);


here the records are successfully added to the Dictionary and after this am binding the Dictionary to a GridView like

C#
gridDept.Datasource=dict;
  gridDept.Databind();


now the inserted records are displayed fine in the gridview. After this am storing this records in the 'StaffDepartments' table in my database. I have 3 columns in the 'Staffdepartments' table

1.StaffId(PK - has link with the Staff table)<br />
 2.DepartmentId(PK - has link with the Department table)<br />
 3.IsHOD.


here the records are stored fine in the database.No problem in adding the records into the database.

I have some questions here

****1.How can check whether the DepartmentId is already there in the Dictionary before adding to it.
2.When am editing the staff detail how can I delete the Selected Department from the Dictionary by checking the checkbox in Gridview rows.(here the records are coming from the database, so when I click delete button the records should be deleted in the database as well)****

if its a List instead of Dictionary, I can get the DepartmentId by

C#
int departmentId = (int)gridDept.DataKeys[row.RowIndex].Values["DepartmentId"];


but in Dictionary i dunno how to do the same with Key and Value pairs....can anyone help me here.
Tags: ASP.NET, Gridview, Dictionary

Plain Text
ASM
ASP
ASP.NET
BASIC
BAT
C#
C++
COBOL
CoffeeScript
CSS
Dart
dbase
F#
FORTRAN
HTML
Java
Javascript
Kotlin
Lua
MIDL
MSIL
ObjectiveC
Pascal
PERL
PHP
PowerShell
Python
Razor
Ruby
Scala
Shell
SLN
SQL
Swift
T4
Terminal
TypeScript
VB
VBScript
XML
YAML

Preview



When answering a question please:
  1. Read the question carefully.
  2. Understand that English isn't everyone's first language so be lenient of bad spelling and grammar.
  3. If a question is poorly phrased then either ask for clarification, ignore it, or edit the question and fix the problem. Insults are not welcome.
  4. Don't tell someone to read the manual. Chances are they have and don't get it. Provide an answer or move on to the next question.
Let's work to help developers, not make them feel stupid.
Please note that all posts will be submitted under the http://www.codeproject.com/info/cpol10.aspx.



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900