473,408 Members | 2,839 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,408 software developers and data experts.

GridView DataBinding to a DataTable and row deleting problems

I have the following gridview. There are 2 other textBoxes and a button on
the page as well. When somebody puts text into the 2 textBoxes and presses
the add button, it puts the values of those textBoxes into the DataTable.
The gridView shows what values have already been entered into the DataTable.
<asp:GridView ID="DefinitionList" runat="server" Caption="Dictionary
entries" EmptyDataText="There are no definitions yet." AllowPaging="True"
AutoGenerateColumns="False" AutoGenerateDeleteButton="True"
AutoGenerateEditButton="True" OnRowDeleting="DefinitionList_RowDeleting"
DataKeyNames="ID">
<Columns>
<asp:BoundField DataField="Word"
HeaderText="Word"></asp:BoundField>
<asp:BoundField DataField="Definition"
HeaderText="Definition"></asp:BoundField>
</Columns>
</asp:GridView>

Here is the code that runs the add button. Everything works fine here the
way I would want it to. The problem comes in with the gridView above. When I
press the delete button, it wipes out the whole DataTable (all of the rows)
not just one of them. How would I make it delete only the row I want to get
rid of?
private void AddDefinition() {
///Todo: Add validation for empty values
Contract StockContract = (Contract)Session["StockContract"];
//Create a linq query to determine if the word already exists in the
dictionary. If it does, return the GridView caption as an error.
var Query = from Counter in StockContract.Dictionary.AsEnumerable() where
Counter.Field<string>("Word") == WordTextBox.Text
select new { Word = Counter.Field<string>("Word") };
if(WordTextBox.Text==String.Empty || DefinitionTextBox.Text ==
String.Empty) {
DefinitionList.Caption = "Empty entries aren't allowed! Type a word and
definition in the boxes above and press the add button.";
}
//Since the word didn't exist in the dictionary, go ahead and add it.
else if(Query.Count()==0) {
DataRow Row = StockContract.Dictionary.NewRow();
Row["Word"] = WordTextBox.Text;
Row["Definition"] = DefinitionTextBox.Text;
StockContract.Dictionary.Rows.Add(Row);
DefinitionList.Caption = "Dictionary entries";
//resave after every add of a word to the dictionary
Session["StockContract"] = StockContract;
} else {
DefinitionList.Caption = "That word is already in the dictionary, try
again!";
}
DefinitionList.DataSource = StockContract.Dictionary;
DefinitionList.DataBind();
WordTextBox.Text = String.Empty;
DefinitionTextBox.Text = String.Empty;
}
Jun 27 '08 #1
0 2360

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

Similar topics

7
by: | last post by:
Hello, Does anyone have an idea on how I can filter the data in the gridview control that was returned by an sql query? I have a gridview that works fine when I populate it with data. Now I...
1
by: j.zascinski | last post by:
Hi, i have a "simple" problem with gridview, please help me :) i want to have gridview which is binded to a datatable (or a dataset). i can show the data from the dataset in the gridview and i can...
4
by: Jim Katz | last post by:
I have an application that updates a strongly typed data set at run time. I'd like to dynamically create a table that connects to a run time data table. For displaying the data, this works well. ...
5
by: sutphinwb | last post by:
Hi - This could be a simple question. When I relate two tables in a datasetet, how do I get that relation to show up in a GridView? The only way I've done it, is to create a separate table in the...
0
by: witek | last post by:
I am lost. There is a dataTable with data which I want to dispaly in GridView. dataTable is not connected to any database. Just dataTable with data. There is a class wich is used as column...
6
by: Kevin Attard | last post by:
I am using a GridView inside a UserControl which has a template column for deleting the rows. Before databinding the gridview i am attaching the RowCommand and RowDataBound event. I am using the...
0
by: =?Utf-8?B?TGFkaXNsYXYgTXJua2E=?= | last post by:
Hello, I read some msdn and other articles about how does databinding among DataSource controls and FormView / GridView controls works but I still don't fully understand to this blackbox. I have...
5
by: NKaufman | last post by:
<asp:GridView ID="Basic" runat="server" DataKeyNames="QuestionID,isHeading" AutoGenerateColumns="false" AllowPaging="true" PageSize="100"> <Columns> <asp:BoundField Visible="false"...
2
by: cmrhema | last post by:
hello, i am new to asp.net. i am trying to do a simple application of adding,inserting and deleting rows in gridview. i am using C#.net and javascript. My edit/update works but i have...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
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,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
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...
0
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...

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.