473,769 Members | 3,823 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Problem in loading gridview after deletion using asp.net(C#)

29 New Member
Hi,
can anybody clear my doubt in asp.net using c#.
i am deleting record in database using gridview control. the problem here is that record gets deleted in database but the changes is not reflected in the gridview control.i also used "gridview1.Data bind()" after delete query. what should i do now?
regards,
a.prabhu
Jun 15 '07 #1
4 2165
dip_developer
648 Recognized Expert Contributor
Hi,
can anybody clear my doubt in asp.net using c#.
i am deleting record in database using gridview control. the problem here is that record gets deleted in database but the changes is not reflected in the gridview control.i also used "gridview1.Data bind()" after delete query. what should i do now?
regards,
a.prabhu
Please post your code snippet.....
Jun 15 '07 #2
Prabhua
29 New Member
Here is my code--

<asp:AccessData Source ID="AccessDataS ource1" DataFile="Datab ase/thecliniq.mdb" SelectCommand=" Select * from tempr" runat="server"> </asp:AccessDataS ource>

<asp:GridView ID="GridView1" DataSourceID="A ccessDataSource 1" AutoGenerateCol umns="false" DataKeyNames ="id" runat="server" HorizontalAlign ="Left" Height="1px" Width="407px" EnableViewState ="False">

<Columns>

<asp:TemplateFi eld>
<HeaderTemplate >
<asp:CheckBox ID="CheckAll" onclick="return check_uncheck (this );" runat="server" />
</HeaderTemplate>
<ItemTemplate >
<asp:Label ID="lbl7" Visible="false" Text='<%# DataBinder.Eval (Container.Data Item, "id") %>' runat="server" />
<asp:CheckBox ID="deleteRec" runat="server" />
<asp:Label ID="addsymptoms " Visible="false" Text='<%# DataBinder.Eval (Container.Data Item, "additionalsymp toms") %>' runat="server"> </asp:Label>
</ItemTemplate>
</asp:TemplateFie ld>

<asp:BoundFie ld DataField="addi tionalsymptoms" HeaderText="Add itional Symtoms" />
<asp:TemplateFi eld HeaderText="sel ect">
<ItemTemplate >
<asp:DropDownLi st ID="DropDownLis t3" DataSource='<%# GetCategoryDesc riptions() %>' DataTextField=" nam" DataValueField= "nam" runat="server">
</asp:DropDownLis t>
</ItemTemplate>
</asp:TemplateFie ld>
</Columns>
<FooterStyle BackColor="Whit e" ForeColor="#000 066" />
<RowStyle ForeColor="#000 066" HorizontalAlign ="Center" />
<SelectedRowSty le BackColor="#669 999" Font-Bold="True" ForeColor="Whit e" />
<PagerStyle BackColor="Whit e" ForeColor="#000 066" HorizontalAlign ="Left" />
<HeaderStyle BackColor="#006 699" Font-Bold="True" ForeColor="Whit e" Width="9555px" HorizontalAlign ="Center" />
</asp:GridView>




this is a code inside click event of delete button--

protected void Delete_Click(ob ject sender, EventArgs e)
{
string gvIDs = "";
bool chkBox = false;
foreach (GridViewRow gv in GridView1.Rows)
{
CheckBox deleteChkBxItem = (CheckBox)gv.Fi ndControl("dele teRec");
if (deleteChkBxIte m.Checked)
{
chkBox = true;
gvIDs = gvIDs + ((Label)gv.Find Control("lbl7") ).Text.ToString () + ",";

}
}
string strConn = "Provider=Micro soft.Jet.OLEDB. 4.0;Data Source=" + Server.MapPath( "Database/thecliniq.mdb") + ";";
OleDbConnection conn = new OleDbConnection (strConn);
conn.Open();


if (chkBox)
{
Response.Write( gvIDs.Substring (0, gvIDs.LastIndex Of(",")));
string deleteOleDb = "DELETE from tempr WHERE id IN (" + gvIDs.Substring (0, gvIDs.LastIndex Of(",")) + ")";
OleDbCommand cmd = new OleDbCommand(de leteOleDb, conn);
cmd.ExecuteNonQ uery();
}
GridView1.DataB ind();
conn.Close();
}
Jun 15 '07 #3
dip_developer
648 Recognized Expert Contributor
Here is my code--

<asp:AccessData Source ID="AccessDataS ource1" DataFile="Datab ase/thecliniq.mdb" SelectCommand=" Select * from tempr" runat="server"> </asp:AccessDataS ource>

<asp:GridView ID="GridView1" DataSourceID="A ccessDataSource 1" AutoGenerateCol umns="false" DataKeyNames ="id" runat="server" HorizontalAlign ="Left" Height="1px" Width="407px" EnableViewState ="False">

<Columns>

<asp:TemplateFi eld>
<HeaderTemplate >
<asp:CheckBox ID="CheckAll" onclick="return check_uncheck (this );" runat="server" />
</HeaderTemplate>
<ItemTemplate >
<asp:Label ID="lbl7" Visible="false" Text='<%# DataBinder.Eval (Container.Data Item, "id") %>' runat="server" />
<asp:CheckBox ID="deleteRec" runat="server" />
<asp:Label ID="addsymptoms " Visible="false" Text='<%# DataBinder.Eval (Container.Data Item, "additionalsymp toms") %>' runat="server"> </asp:Label>
</ItemTemplate>
</asp:TemplateFie ld>

<asp:BoundFie ld DataField="addi tionalsymptoms" HeaderText="Add itional Symtoms" />
<asp:TemplateFi eld HeaderText="sel ect">
<ItemTemplate >
<asp:DropDownLi st ID="DropDownLis t3" DataSource='<%# GetCategoryDesc riptions() %>' DataTextField=" nam" DataValueField= "nam" runat="server">
</asp:DropDownLis t>
</ItemTemplate>
</asp:TemplateFie ld>
</Columns>
<FooterStyle BackColor="Whit e" ForeColor="#000 066" />
<RowStyle ForeColor="#000 066" HorizontalAlign ="Center" />
<SelectedRowSty le BackColor="#669 999" Font-Bold="True" ForeColor="Whit e" />
<PagerStyle BackColor="Whit e" ForeColor="#000 066" HorizontalAlign ="Left" />
<HeaderStyle BackColor="#006 699" Font-Bold="True" ForeColor="Whit e" Width="9555px" HorizontalAlign ="Center" />
</asp:GridView>




this is a code inside click event of delete button--

protected void Delete_Click(ob ject sender, EventArgs e)
{
string gvIDs = "";
bool chkBox = false;
foreach (GridViewRow gv in GridView1.Rows)
{
CheckBox deleteChkBxItem = (CheckBox)gv.Fi ndControl("dele teRec");
if (deleteChkBxIte m.Checked)
{
chkBox = true;
gvIDs = gvIDs + ((Label)gv.Find Control("lbl7") ).Text.ToString () + ",";

}
}
string strConn = "Provider=Micro soft.Jet.OLEDB. 4.0;Data Source=" + Server.MapPath( "Database/thecliniq.mdb") + ";";
OleDbConnection conn = new OleDbConnection (strConn);
conn.Open();


if (chkBox)
{
Response.Write( gvIDs.Substring (0, gvIDs.LastIndex Of(",")));
string deleteOleDb = "DELETE from tempr WHERE id IN (" + gvIDs.Substring (0, gvIDs.LastIndex Of(",")) + ")";
OleDbCommand cmd = new OleDbCommand(de leteOleDb, conn);
cmd.ExecuteNonQ uery();
}
GridView1.DataB ind();
conn.Close();
}
Databind () method binds gridview with the datasource you supply....
where is the updated datasource after deletion????? or am I overlooking something??
Jun 15 '07 #4
Prabhua
29 New Member
By default Gridview control will take data from Accessdatasourc e control,right? which is indicated in .aspx file.
Jun 15 '07 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

5
15332
by: Brian McClellan | last post by:
Just wondering if anyone has a simple example of creating a gridview completely programmatically, i'm not doing anything terribly sophisticated. When creating the gridview declaratively evertying works fine, however programmatically, while the grid will display data that exsists in the database, any operation on the data ( editing/updating/deleting ) seems to cause a rowdeleting/updating etc error. Or is this simply not meant to be done?
0
1371
by: ASMJ | last post by:
Hi, I have a gridview in my page, which displays all records from an sqldatasource. The delete row command is available to the user, through which he can perform deletion. I want to trap the gridview_RowDeleting event to display a confirmation msg to the user. Is there a msgbox kind of facility where I can get confirmation from the user before deletion?
7
5382
by: GaryDean | last post by:
I'm trying to load a GridView up with data manually, in code. I'm not using any datasource. Using this code.... ArrayList myRowArrayList; GridViewRow myGVR = new GridViewRow(0,0,DataControlRowType.DataRow, DataControlRowState.Normal); TableCell myCell = new TableCell(); TextBox myTextbox = new TextBox(); myTextbox.Text = "hello world"; myCell.Controls.Add(myTextbox);
0
2417
by: John Smith | last post by:
ASP.Net 2.0 / C# / IIS 6 I have 2 pages. The master page consists of a tabbed menu created using the Menu and MultiView controls. Something like this: http://fredrik.nsquared2.com/viewpost.aspx?PostID=344&showfeedback=true The second page is a user control that contains a GridView control linked to a database table. What's supposed to happen is that the user clicks on a menu choice and an appropriate user control will load. For...
2
429
by: Loading name... | last post by:
Hey asp.net 2.0 I have a GridView on my webpage. This GridView's datasource is a SqlDataSource. The SqlDataSource returns 3 columns. Here is my problem: My GridView consist of 3 columns (id column + 2 text columns). I want to hide the id column, and change the formating of the text columns. I've tryed
4
1882
by: ma | last post by:
Hello, I have a GrideView that has 4 col. 3 of them are bound to a dataset and the last one is not. The last one is check box. The check box is defined as follow: <asp:TemplateField HeaderText="Select">
2
4919
by: DC | last post by:
Hi, I am trying to implement a simple template control (to be used as TemplateItem etc. in GridView). Does someone see why my code fails? I give up for now and try a different approach (http:// www.developerfusion.co.uk/show/4721). TIA for any ideas. Regards DC
0
1696
by: db007 | last post by:
I have a problem at the moment with a web project. I have two Panels within an UpdatePanel on an aspx page (using Masterpages). I'm using ASP.Net 2.0 with an AJAX enabled website. The two Panels represent a Master-Detail type relationship. I want a user to click a LinkButton in the first Panel and then for the 2nd Panel to be displayed with the detail. However, I need to set some text properties of textboxes programmatically when the...
2
2322
by: =?Utf-8?B?QXN0cml0aA==?= | last post by:
I am a Newbie and i am scratching my head over how to delete a Row from a GridView. I have this GridView which has 3 fields called ID,ProjCode and ProjDescription of which ID is the hidden field. I have also set the property AutoGenerateDeleteButton="True". Now as i understand, i have to write code in the GridView1_RowDataBound and GridView1_RowDeleting METHODS to perform deletion of row. I have been searching for long for the code...
0
9579
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9851
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...
0
8863
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6662
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
5293
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5441
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3949
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
3556
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2811
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.