Hi
I m looking for some sample example (Code) for my following scenario
I have a Grid View which populates data from database say from Product Tables
using dataset and dataadapter
This Grid has three columns of productid ,ProductName ,Unit Price (THis is editable text box field). There is checkbox column. (Paging is enabled there are 2 pages )
There are three buttons say update and delete
Now suppose I select 5 checkboxes and
1) click update then watever changes I have done should be reflected in database
2)click delete then those five rows should be deleted in database.
and my page should be refreshed.
(ALL THESE SHOULD BE DONE WITHOUT USING SQLDATASOURCE OR ANY OTHER INBUILT .NET stuff)
Any help will be greatly appreciated
10 4084
What have you done so far? Please read the faqs you are not following the site rules. Thanks.
I didn't get u.
I guess you are saying me to put code watever I have done till now??
What have you done so far? Please read the faqs you are not following the site rules. Thanks.
Not necessary that it should be the code.
But are you asking us to make that for you? or are you asking for help in that?
We can help you if you are facing issues with your current work or if something isint working, Please do mention what you have started with that so that we can guide you in the right direction.
PS: Do not enter text in Caps lock, this is against the site regulations!
Hi
Below is the part of code .
Here in BtnSubmit_Click Event I m able to find which all check box was clicked and wat value was changed but after this I need help how to update database with these values using a gud design. -
<%@ Page Language="C#" Trace="false" Debug="true" AutoEventWireup="true" CodeFile="GridTemplate.aspx.cs" Inherits="GridTemplate" %>
-
-
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
-
-
<html xmlns="http://www.w3.org/1999/xhtml" >
-
<head runat="server">
-
<title>Untitled Page</title>
-
</head>
-
<body>
-
<form id="form1" runat="server">
-
<div>
-
<asp:GridView ID="GridBind" runat="server" AutoGenerateColumns="False" style="left: 261px; position: absolute; top: 9px" Height="294px">
-
<Columns>
-
<asp:TemplateField HeaderText="Select">
-
<ItemTemplate>
-
<asp:CheckBox ID="chek" runat="server" />
-
</ItemTemplate>
-
-
</asp:TemplateField>
-
<asp:TemplateField HeaderText="Product ID" SortExpression="ProductID">
-
<ItemTemplate >
-
<asp:label ID="ProductId" Width="40" Text='<%#Eval("ProductID")%>' runat="server"/>
-
</ItemTemplate>
-
</asp:TemplateField>
-
<asp:TemplateField HeaderText="Unit Price" SortExpression="UnitPrice">
-
<ItemTemplate>
-
<asp:label ID="UnitPrice" Width="40" Text='<%#bind("UnitPrice")%>' runat="server"/>
-
</ItemTemplate>
-
<EditItemTemplate>
-
<asp:TextBox ID="UnitPrice" Width="40" Text='<%#bind("UnitPrice")%>' runat="server"/>
-
</EditItemTemplate>
-
</asp:TemplateField>
-
<asp:TemplateField HeaderText="Product Name" SortExpression="ProductName">
-
<ItemTemplate>
-
<asp:TextBox ID="ProductName" Width="40" Text='<%#bind("ProductName")%>' runat="server"/>
-
</ItemTemplate>
-
</asp:TemplateField>
-
</Columns>
-
</asp:GridView>
-
<br />
-
<br />
-
<asp:Button ID="btnsubmit" runat="server" OnClick="btnsubmit_Click" Style="left: 338px;
-
position: absolute; top: 341px" Text="submit" />
-
-
</div>
-
</form>
-
</body>
-
</html>
-
-
using System;
-
using System.Data;
-
using System.Configuration;
-
using System.Collections;
-
using System.Collections.Generic;
-
using System.Web;
-
using System.Web.Security;
-
using System.Web.UI;
-
using System.Web.UI.WebControls;
-
using System.Web.UI.WebControls.WebParts;
-
using System.Web.UI.HtmlControls;
-
using System.Data.SqlClient;
-
-
-
public partial class GridTemplate : System.Web.UI.Page
-
{
-
private DataView dv;
-
protected void Page_Load(object sender, EventArgs e)
-
{
-
if (!Page.IsPostBack)
-
DataBindingGrid();
-
}
-
private void DataBindingGrid()
-
{
-
-
string Conn1 = @"Data Source=XYZ\SQLEXPRESS;Initial Catalog=Northwind;Integrated Security=True";
-
SqlConnection conn = new SqlConnection(Conn1);
-
SqlCommand cmd = new SqlCommand();
-
cmd.CommandType = CommandType.Text;
-
cmd.CommandText = "Select top 20 ProductID,ProductName,UnitPrice from Products";
-
cmd.Connection = conn;
-
SqlDataAdapter sqda = new SqlDataAdapter(cmd);
-
DataSet ds = new DataSet();
-
sqda.Fill(ds, "Product");
-
GridBind.DataSource = ds.Tables["Product"];
-
GridBind.DataBind();
-
}
-
-
protected void btnsubmit_Click(object sender, EventArgs e)
-
{
-
List<int> rowid = new List<int>();
-
List<string> unitprice = new List<string>();
-
foreach (GridViewRow row in GridBind.Rows)
-
{
-
CheckBox chk1 = (CheckBox)row.Cells[0].FindControl("chek") as CheckBox;
-
if (chk1.Checked)
-
{
-
rowid.Add(row.RowIndex);
-
TextBox txtb = (TextBox)row.Cells[3].FindControl("ProductName") as TextBox;
-
-
unitprice.Add(txtb.Text);
-
}
-
}
-
}
-
}
a
You know how you grabbed data from the database to populate your GridView?
It's basically the same thing for when you want to update your database.
Just connect to it and update the row that's been edited with the information the user provided....
For more help with using a database, please see How to use a database in your program.
-Frinny
Here Once I click submit then how can I can use dataset or datable and there different properties to find out which rows were updated and then use them to update my database.
I only know how to these updates using ExecuteNonQuery on command objects but never used dataset or dataadapter.
I m very new with disconnected architecture of ADO .NET especially updation part.
You know how you grabbed data from the database to populate your GridView?
It's basically the same thing for when you want to update your database.
Just connect to it and update the row that's been edited with the information the user provided....
For more help with using a database, please see How to use a database in your program.
-Frinny
Here Once I click submit then how can I can use dataset or datable and there different properties to find out which rows were updated and then use them to update my database.
I only know how to these updates using ExecuteNonQuery on command objects but never used dataset or dataadapter.
I m very new with disconnected architecture of ADO .NET especially updation part.
Do you have a column in your GridView for an "edit button"?
When the user clicks the edit button they're able to make changes to the data within the GridView. Once they've finished they click "save" or "update" (or whatever the button says) and this raises a RowUpdated event. You should implement the method that handles this event.
See the GridView class for more details, examples, and how-tos.
See the DataSet Class for more information on how to use a DataSet. And take a look at Using DataSets in ADO.NET.
Cheers!
-Frinny
hi
In my case I have to update some (ex 3 to 4) rows data at once on click of submit(which is not part of GridView control on form ) button on form.
I m not using Edit and update button for individual button .Here updation will be done for all selected at once.
Thanks
Gagan
hi
In my case I have to update some (ex 3 to 4) rows data at once on click of submit(which is not part of GridView control on form ) button on form.
I m not using Edit and update button for individual button .Here updation will be done for all selected at once.
Thanks
Gagan
Did you take a look at the link I gave you on using DataSets in ADO.NET?
On that site you would have found a link that lead you to Updating Data Sources with DataAdapters. There is an example there on how to use your DataSet to update the database.
-Frinny
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Phillip J. Eby |
last post by:
PEP: 333
Title: Python Web Server Gateway Interface v1.0
Version: $Revision: 1.1 $
Last-Modified: $Date: 2004/08/27 17:30:09 $
Author: Phillip J. Eby <pje at telecommunity.com>
Discussions-To:...
|
by: Marina Anufreichik |
last post by:
Hi,
After deploymnet web application on web server I can access page on local
machine and login fine but when I'm trying to access web site from remote
machine I can see login page, but when I'm...
|
by: Jeremy Ames |
last post by:
I have created a web application that uses a custom control and a web
service on my local system. I have gotten all of the bugs worked out on my
local system and now it is time to move it to the...
|
by: Diego F. |
last post by:
I've been days with that. I'm trying to work with web services sending and
returning objects, and the web service must store some objects.
- My first try (the most obvious in my opinion) was to use...
|
by: C. Woody Butler |
last post by:
I have a strange problem with a website and a web service.
They're both on the same server, running Windows server 2003. The website is
set up as the default website for the server.
I've got...
|
by: Baruaa |
last post by:
hi i m asheesh ,
can any on ehelp me about this error.
Line 57: -->
Line 58: <httpHandlers>
Line 59: <add verb="*" path="*.vb"
type="System.Web.HttpNotFoundHandler,System.Web" />
|
by: Ruslan |
last post by:
Hello,
I have to project: one ASN.NET project and another - Web Service in the same
solution. I want to use the same web.config and global.asax files. Does it
possible?
|
by: Erick Lopez |
last post by:
When I send my web page to browser in ouput windows recibe this message
and the web page the error BC32400
Please Help me
Auto-attach to process ' aspnet_wp.exe' on machine 'TABLET'...
|
by: Jonas |
last post by:
Hi.
I'm trying to develop a web custom control that uses a programmatically
created treeview.
My problem is that I get an exception when I try to render the control.
With properties do I have to...
|
by: =?Utf-8?B?YW5vbg==?= |
last post by:
I am not sure if this is the right forum.
Environment : Windows server 2008, IIS 7.0
I get the 'Could not load the file or assembly 'blowery.web.httpCompress' or
one of its dependencies. The...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: ryjfgjl |
last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
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...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
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...
|
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,...
|
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,...
|
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...
| |