473,804 Members | 2,931 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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="DefinitionL ist" runat="server" Caption="Dictio nary
entries" EmptyDataText=" There are no definitions yet." AllowPaging="Tr ue"
AutoGenerateCol umns="False" AutoGenerateDel eteButton="True "
AutoGenerateEdi tButton="True" OnRowDeleting=" DefinitionList_ RowDeleting"
DataKeyNames="I D">
<Columns>
<asp:BoundFie ld DataField="Word "
HeaderText="Wor d"></asp:BoundField>
<asp:BoundFie ld DataField="Defi nition"
HeaderText="Def inition"></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)Sessi on["StockContr act"];
//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.D ictionary.AsEnu merable() where
Counter.Field<s tring>("Word") == WordTextBox.Tex t
select new { Word = Counter.Field<s tring>("Word") };
if(WordTextBox. Text==String.Em pty || DefinitionTextB ox.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.D ictionary.NewRo w();
Row["Word"] = WordTextBox.Tex t;
Row["Definition "] = DefinitionTextB ox.Text;
StockContract.D ictionary.Rows. Add(Row);
DefinitionList. Caption = "Dictionary entries";
//resave after every add of a word to the dictionary
Session["StockContr act"] = StockContract;
} else {
DefinitionList. Caption = "That word is already in the dictionary, try
again!";
}
DefinitionList. DataSource = StockContract.D ictionary;
DefinitionList. DataBind();
WordTextBox.Tex t = String.Empty;
DefinitionTextB ox.Text = String.Empty;
}
Jun 27 '08 #1
0 2383

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

Similar topics

7
14823
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 want to look at that data and filter it based on what is in it. I know that this could have been done with data sets and data views in asp.net 1.1 but how is this done now in asp.net 2.0?
1
9200
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 start editing the data, but when i click update i loose my new values. I want this values to be saved in datatable (not straight to database with sqldatasource - i tried this and it worked great), i tried to do this task with objectdatasource...
4
13497
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. I just set the GridView.DataSource once, and call DataBind(); I'd like to drive the application from the GridView control, by including command buttons that allow editing of the data. Starting out simple, I have a DataTable with a boolean...
5
6458
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 dataset with a join query for the GetData() select method. I use ObjectDataStore to couple the GridView with the table adapter on the dataset. If I point the ODS at the child table, the GridView will bind to the "normal" select and I end up...
0
2700
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 template //------------------------------------------------------------------------------------------------------- public class TextBoxTemplate :ITemplate { DataControlRowType m_rowType;
6
28178
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 RowDataBound event to set the commandargument of the delete button. The event is being fired and works fine. When I press the delete button, the RowCommand event is not firing! and neither is the RowDeleting (the button's commandName is...
0
2000
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 few questions and hopefully you can provide me some answers. 1. Best place for DataBinding. Where is the best place for calling DataBind method? Is it possible to say don't bind controls for this postback and use current values instead? These...
5
23636
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" DataField="QuestionID" HeaderText="QuestionID"></asp:BoundField> <asp:BoundField DataField="QuestionDesc" HeaderText="Question" ItemStyle-HorizontalAlign="Left"></ asp:BoundField>
2
2457
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 problems in deleting the rows in the datagrid. i have used command fields(properties-columns) edit,update,cancel and delete commands. i changed it to template field. both are as buttons. ihave changed the id of Delete command to btDelete. The...
0
10325
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10315
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
10075
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...
1
7615
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
6847
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
5651
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4295
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
3815
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2990
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.