Save Data Into Table Before Deleting - c#

I have a detailview that has the Delete button; when user clicks the Delete button they get the delete confirmation dialog box. What kind of command do i need to use in the detailview before the data gets deleted? When user selects "Yes" i want to save the data in the detailview into some kind of variable first then delete it. I want to get some kind of high level guidance or some hint. thanks
Here is the code for the confirmation dialog box in my ASPX file.
<ItemTemplate>
<asp:Button ID="Button1" runat="server" CausesValidation="False"
CommandName="Edit" Text="Edit" />
<asp:Button ID="Button2" runat="server" CausesValidation="False"
CommandName="Delete" Text="Delete" OnClientClick="return confirm('Are you sure you want to delete');" />
</ItemTemplate>

Subscribe to the ItemDeleting event, or even the ItemCommand event.
In both you will still be able to access the data before it is deleted.

Related

Gridview Select button no longer works after adding delete button

Ever since I added the Delete button, the Select button no longer redirects to another page when clicked. I added an alert on the OnSelectedIndexChanged and that worked so I am not sure why it no longer redirects. Also, if I remove the delete button the redirect works but I need both buttons.
<asp:CommandField ButtonType="Button" ShowSelectButton="True"></asp:CommandField>
<asp:TemplateField>
<ItemTemplate>
<asp:Button ID="btnDeleteRecord" runat="server" Text="Delete" CommandName="Delete"
OnClientClick="return confirm('Are you sure you want to delete this item?');" />
</ItemTemplate>
</asp:TemplateField>
OnSelectedIndexChanged. If I removed false it didn't matter either.
protected void listIndexView_SelectedIndexChanged(object sender, EventArgs e)
{
Response.Redirect("mypage.aspx", false);
}
Hum, I can't say I seen this behvaour.
But, just drop in two templated buttons and you off to the races so to speak. Because you NOT REALLY using the built in edit and features of those buttons, then little is to be gained by "half" using the built in buttons that way. So just template two buttons like this:
<asp:TemplateField>
<ItemTemplate>
<asp:Button ID="btnSelectD" runat="server"
Text="Select" CommandName="Select" />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField>
<ItemTemplate>
<asp:Button ID="btnDeleteRecord" runat="server"
Text="Delete" CommandName="Delete"
OnClientClick="return confirm('Are you sure you want to delete this item?');" />
</ItemTemplate>
</asp:TemplateField>
And as a result, you are free to attach events to each button to do whatever you want.
Note in the code editor, you will see this during editing of the markup and you ARE given a chance to create + add a event stub for buttons inside of that gridview etc.
Now if the button was outside of the gridview/listview/repeater etc., then you can normally just double click on the button and jump to the codebehind IDE. But when the button is inside of a repeating object, then you can't double click to create + build the event stub, but if you edit in markup as per above, then note how you see that dropdown appear - and you can choose create new event. Choose that, but you THEN have to flip over to code behind - and you will/should see the code stub.

Redirect to a form on button click in Grid View

I have build a GridView on a webpage, having two ButtonFields columns: Accept and Reject. Now when I click on Reject button, I want to show a popup form with some input fields and store that data into the Database.
I'm just stuck at showing the popup on clicking the reject button field. Is this possible?v
put code in .aspx file
<asp:TemplateField HeaderText="Edit" itemstyle-width="150px">
<ItemTemplate>
<asp:LinkButton ID="btnEdit" runat="server" CommandName="Edit" Text="Edit" CausesValidation="false"/>
</ItemTemplate>
</asp:TemplateField>
put code in .cs file
if (e.CommandName.Equals("Edit"))
{
string QueryString="val";
Page.ClientScript.RegisterStartupScript(GetType(), "", "window.open('Page.aspx?QS=" + QueryString + "','','width=500,height=500');"", true);
}

ASP.NET C# checbox select after searching gridview

I have a problem with update panel which contains gridview (dynamically generated). Every row in gridview contains checbox, name of person and surname of person.
When user click on close button then every value (name) of selected row is saved in cookie (using jquery and asp.net-hidden value). That is working all right.
Problem appears here:
I also have possibility to search after name or surname of persons, becuase there are a lot of persons and that should help user to quickly find a right person.
Let say that I have this data:
Checbox1 John Doe
Checkox2 Michael Clark
Checbox1 (John Doe) is already selected.
So when I typed Clark in Surname textbox and click button "Search" gridview is generated again and there is one row (Michael Clark). When user select checbox of Michael Clark and click close button than cookie has only one value (Michael Clark, John Doe is logically missing).
<asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode="Conditional">
<ContentTemplate>
<asp:Panel ID="Panel1" runat="server" DefaultButton="isciPodjetja">
<asp:TextBox ID="namePerson" runat="server" />
<asp:TextBox ID="surnamePerson" runat="server" />
<asp:Button ID="Searchperson" runat="server" Text="Search" OnClick="Serachperson_Click" />
</asp:Panel>
<p />
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False">
<Columns>
<asp:TemplateField HeaderText="SelectALL">
<HeaderTemplate>
<asp:CheckBox ID="chkBxHeader" runat="server" onclick="javascript:SelectAllCheckboxes1(this);" />
</HeaderTemplate>
<ItemTemplate>
<asp:CheckBox ID="chkSelected" runat="server" OnCheckedChanged="chkSelected_CheckedChanged"/>
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="NAME" HeaderText="Name of person"></asp:BoundField>
<asp:BoundField DataField="SURNAME" HeaderText="Surname of person" </asp:BoundField>
</Columns>
</asp:GridView>
</ContentTemplate>
</asp:UpdatePanel>
Any Idea how can I implement that searching more easily? I tried with adding OnCheckedChanged to checbox, but autopostback does not work fine (when I clicked on checbox it is checked for a second, then is unchecked again).
Best solution for me would be, that when user click on search button than just hover appear on a correct row. Is it possible?
You have to develop two function in javascript begin request and end request.You have to write your javascript or jquery function in onbeginrequest() and onendrequest(), then only it will be fired. Please check it.
I solved my problem. I used javascript quicksearch plugin from https://github.com/riklomas/quicksearch.

Disable the asp button after first click because it save multiple records in slow connection

<asp:Button
ID="btnUpdate"
runat="server"
OnClick="btnUpdate_Click"
Text="Update"
CssClass ="btn"
ToolTip="Update"
Width="58px" />
`This is my code for button, want to use javascript..help plz
Very easy to do to prevent the user pressing it twice - here is an example of using JavaScript to hide the button.
<asp:Button ID="btnUpdate" runat="server" OnClick="btnUpdate_Click"
OnClientClick="this.style.visibility = 'hidden';"
Text="Update" CssClass ="btn" ToolTip="Update" Width="58px" />
You should do it clientside, using javascript and not using C# code.
Try to Add OnClientClick event on the button and disable it on the event.

GridView edit command button with jquery

I want to use the gridview command button (edit) with the jquery not postback. Please help me.
Place an asp button in another item template and set its CommandName property to edit. This will work simillar to default edit button in grid view. Then you can call javascript function and perform your logic.
See the code below:
Remove the following line to avoid default edit button:
<asp:CommandField ShowEditButton="true" ShowCancelButton="true"/>
Add the following instead:
<asp:TemplateField HeaderText="headerName" >
<ItemTemplate>
<asp:Button ID="Button1" CommandName="edit" runat="server" Text="Button" />
</ItemTemplate>
</asp:TemplateField>
Hope this helps you..
I think you can do it in a gridview.What you need is to columns with textbox and display the data in the textbox and needs a button at the end .
<asp:TemplateField >
<HeaderTemplate>
Values
</HeaderTemplate>
<ItemTemplate>
<asp:textbox ID"txt" runat="server" cssclass="abc" />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Spares">
<HeaderTemplate>
Edit column
</HeaderTemplate>
<ItemTemplate>
<asp:button id="abc" runat="server" text="save" cssclass="pqr" />
<input type="hidden" runat="server" value="" />
</ItemTemplate>
</asp:TemplateField>
Store the Id in a hidden field and it is possible to get the value of text box and hidden feild via jquery.
gridview will be rendered as html table and using parent() we can able to find the clicked row and after finding the row u can use find() to find the values in the txtbox and hidden feild. Use $ajax() or $post() to send data to server.

Categories

Resources