Edit a DataControl (without using Edit Mode)

Hi

is it possible to edit a data control (i will use datalist or detailsview) with clicking a linkbutton (not data control's edit mode) ?

my link button in a division and my data control is in another division so i think i have to find a solution to change my datacontrol's mode to edit with clicking a button.

0
elephantman
3/3/2009 9:23:53 PM
asp.net.presentation-controls 72751 articles. 3 followers. Follow

4 Replies
858 Views

Similar Articles

[PageSpeed] 17
Get it on Google Play
Get it on Apple App Store

A simple example

 

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default4.aspx.cs" Inherits="Default4" %>

<!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>
        <br />
        <br />
        <br />
        <asp:DetailsView ID="DetailsView1" runat="server" AllowPaging="True" AutoGenerateRows="False"
            DataKeyNames="CategoryID" DataSourceID="SqlDataSource1" Height="50px" Width="499px">
            <Fields>
                <asp:BoundField DataField="CategoryID" HeaderText="CategoryID" InsertVisible="False"
                    ReadOnly="True" SortExpression="CategoryID" />
                <asp:BoundField DataField="CategoryName" HeaderText="CategoryName" SortExpression="CategoryName" />
                <asp:BoundField DataField="Description" HeaderText="Description" SortExpression="Description" />
            </Fields>
        </asp:DetailsView>
        <asp:Button ID="BtnEdit" runat="server" OnClick="BtnEdit_Click" Text="Edit" />
        <asp:Button ID="BtnSave" runat="server" OnClick="BtnSave_Click" Text="Save" Visible="False" />
        <asp:Button ID="BtnCancel" runat="server" OnClick="BtnCancel_Click" Text="Cancel"
            Visible="False" /><br />
        <br />
        <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:NorthwindConnectionString2 %>"
            DeleteCommand="DELETE FROM [Categories] WHERE [CategoryID] = @CategoryID" InsertCommand="INSERT INTO [Categories] ([CategoryName], [Description]) VALUES (@CategoryName, @Description)"
            SelectCommand="SELECT * FROM [Categories] ORDER BY [CategoryName]" UpdateCommand="UPDATE [Categories] SET [CategoryName] = @CategoryName, [Description] = @Description WHERE [CategoryID] = @CategoryID">
            <DeleteParameters>
                <asp:Parameter Name="CategoryID" Type="Int32" />
            </DeleteParameters>
            <UpdateParameters>
                <asp:Parameter Name="CategoryName" Type="String" />
                <asp:Parameter Name="Description" Type="String" />
                <asp:Parameter Name="CategoryID" Type="Int32" />
            </UpdateParameters>
            <InsertParameters>
                <asp:Parameter Name="CategoryName" Type="String" />
                <asp:Parameter Name="Description" Type="String" />
            </InsertParameters>
        </asp:SqlDataSource>
    </div>
    </form>
</body>
</html>

 

using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;

public partial class Default4 : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }
  
    protected void BtnEdit_Click(object sender, EventArgs e)
    {
        DetailsView1.ChangeMode(DetailsViewMode.Edit);
        BtnCancel.Visible = true;
        BtnSave.Visible = true;
        BtnEdit.Visible = false;
    }
    protected void BtnSave_Click(object sender, EventArgs e)
    {
        DetailsView1.UpdateItem(false);
        BtnEdit.Visible = true;
        BtnCancel.Visible = false;
        BtnSave.Visible = false;

    }
    protected void BtnCancel_Click(object sender, EventArgs e)
    {
        DetailsView1.ChangeMode(DetailsViewMode.ReadOnly);
        BtnEdit.Visible = true;
        BtnCancel.Visible = false;
        BtnSave.Visible = false;

    }
}
 
Please Mark As Answer posts that helped you.

"If we learn from our mistakes, I should be brilliant by now."

0
nikki_doer_of_things
3/3/2009 10:24:08 PM

thanks for the example

i did an example for myself to try the code but i failed :(

here is my detailsview

<asp:DetailsView ID="DetailsView1" runat="server" AutoGenerateRows="false">

<Fields>

<asp:TemplateField>

<ItemTemplate>

<asp:Label ID="lbl1" runat="server" Text=""><%# Eval("dogid") %></asp:Label><br />

<asp:Label ID="lbl2" runat="server" Text=""><%# Eval("dogname") %></asp:Label>

 

</ItemTemplate>

 

<EditItemTemplate>

 

 

<div style="vertical-align:middle; text-align:right; height:20px"> EDIT MENU</div>

<br /><br /><br /><br />

<table cellpadding="2" cellspacing="3">

<tr>

<td>

<strong>DOG ID:</strong>

<asp:TextBox ID="txtDogId" runat="server" Text="" Width="250px"></asp:TextBox>

 

</td>

<tr>

<td>

<strong>DOG NAME:</strong>

<asp:TextBox ID="txtDog" runat="server" Text="" Width="250px"></asp:TextBox>

</td>

</tr>

</table>

 

</EditItemTemplate>

</asp:TemplateField>

 

</Fields>

</asp:DetailsView>

<asp:LinkButton ID="LinkButton1" runat="server" OnClick="LinkButton1_Click">LinkButton</asp:LinkButton>

 

and my code behind:

protected void Page_Load(object sender, EventArgs e)

{

Doldur();

}

private void Doldur()

{

int deger1 = 1;string deger2 = "Dog1";

 

DataTable dt = new DataTable();

DataRow dr;

dt.Columns.Add(new System.Data.DataColumn("dogid", typeof(Int32)));

dt.Columns.Add(new System.Data.DataColumn("dogname", typeof(String)));

 

 

dr = dt.NewRow();

dr[0] = deger1;

dr[1] = deger2;

dt.Rows.Add(dr);

 

DetailsView1.DataSource = dt;

DetailsView1.DataBind();

}

protected void LinkButton1_Click(object sender, EventArgs e)

{

DetailsView1.ChangeMode(
DetailsViewMode.Edit);

}

 

However i didnt get any error it doesnt turn to the edit template in detailsview i cant see my textboxes so i cant edit them.

Could you tell me what is my mistake?

 

Thank You

0
elephantman
3/3/2009 10:55:40 PM

Hi ,

Change code to :

protected void LinkButton1_Click(object sender, EventArgs e)

{

DetailsView1.ChangeMode(
DetailsViewMode.Edit);

Doldur();

}

protected void Page_Load(object sender, EventArgs e)

{

if(!IsPostBack)

Doldur();

}



Samu Zhang
Microsoft Online Community Support

Please remember to click “Mark as Answer” on the post that helps you, and to click “Unmark as Answer” if a marked post does not actually answer your question.
0
Samu
3/6/2009 4:33:26 AM

thank you it works great now

0
elephantman
3/7/2009 12:20:56 PM
Reply:

Similar Artilces:

Edit control is not loaded in edit mode
I have a problem that the dynamic data field edit control (such as TEXT_edit.ascx) is not loaded when in edit mode. Instead, the normal view control is loaded (such as Text.ascx). In debug I can determina the page mode is truly edit mode. Please help! Could you provide some more context: is this in a custom page with a custom column set or one of the default scaffold pages? Are you using a UIHintAttribute? Make sure the names of the display and edit versions match.Marcin DoboszSDE, ASP.NET Team, MicrosoftRead my blog This is just a thought are you using Views rather than ...

Add new controls to a gridview row; when editing that row using the edit row feature in the gridview control.
Hi all  I have a questions that looks hard / complex to me, and i know you can help me in this. Q {  I have row in a Gridview and i have an edit option to it. I press the edit button, to edit the values in that row and update data all the way back to the database. Now when i press the edit button, i want a drop down list to be displayed that contain values for a particular field in my grid view. (for now only plain text boxes appear.) } I hope you understand my question, all i need to do is replace the text box controls with a dropdown list when i am editing a row in ...

How to edit DataGrid without using Edit,updatebutton buttons?
Hi,   I want to edit and update edited values in the datagrid without using EDIT button.   My requirement is, when i click the particular column[cell, not header] only that column has to display textbox.   OR   When i click the one cell, total column has to displays taxtboxes..   Looking for someone help.   Pradeep Kumar Bura...

using javascript getting value from textbox when edit button is clicked and both controls are present in gridview control
Hi All using javascript I want to get value  from textbox when edit button is clicked and both controls that is texbox and button are present in gridview control .Alok Hi aloksinha83, Please see this post: http://forums.asp.net/t/1069245.aspx Thanks,Qin Dian TangMicrosoft Online Community SupportPlease remember to mark the replies as answers if they help and unmark them if they provide no help....

To edit or no to edit
Jon, Can I edit, whatever I've written so far, so that it doesn't look like I wrote utterly crap?-) -- Pieter "Linux is like living in a teepee. No Windows, no Gates, Apache in house." -- Usenet signature Pieter Zijlstra wrote: > Jon, > > Can I edit, whatever I've written so far, so that it doesn't look like > I wrote utterly crap?-) Oh boy, the edit button vanished from the web-forum ... ;-) -- Pieter "Humor is also a way of saying something serious." -- T. S. Eliot (1888 - 1965) Pieter Zijlstra wrote: ...

Editable/Not Editable
Hello All, I have some webform(.aspx page) in which i have some controls (for input) and i would like to make that screen editable/not editable based on some condition. how can i do that.  the whole intent is user can read the information but can't change.  shiva kumar If you want to make the controls editable/non-editable, you can set their ReadOnly property to true or false accordingly. What exactly do you imply by making the screen editable/non-editable?Thanks,MaxLet Me Google That For You! i mean to say i would like to show the current values but user should not mod...

MXDatagrid edit without using 'Edit' button
I have created a MXdatagrid in the Web Matrix environment. I want to be able to select a line in the datagrid using the 'Select' button and pass the column values to a child-web form for editing. I want to keep autogeneratefields=false. Is there a way to do this? The reason I don't want to use the 'Edit' button provided is due to the fact that the autogeneratefields must = true to use this feature. Also, when editing directly in the MXdatagrid, I cannot use dropdownlists to limit entries made by my users. I am very new to ASP.NET, if you couldn't tell, and would appreciate all the ...

Any trick to edit any colmun in a TListview control report mode? [Edit]
I mean every subitems from the list (report mode), not just the caption, editing done within the list itself. Or any third-party TListView derived from Delphi TListView that do allow it (not TVirtualStringTree). Thanks. <richard poulin> wrote in message news:104692@forums.codegear.com... > I mean every subitems from the list (report mode), not just the caption, > editing done within the list itself. How to use the Build-in Editor of TListView to Edit SubItems http://cc.embarcadero.com/Item/23873 -- Remy Lebeau (TeamB) > {quote:title=Remy Lebeau (TeamB) wrote:...

Edit but no edit
I've Created a custom module and reuse the survey.dnn file to help with the install here it is. <?xml version="1.0" encoding="utf-8" ?> <dotnetnuke version="2.0" type="Module"> <folders> <folder> <name>CompanyName - Photos</name> <description>Photos allows you to add photo albums</description> <version>01.00.00</version> <modules> <module> <friendlyname>CompanyName - Photos</friendlyname> <controls> <c...

How to use FormView 's edit, cancel, insert and delete without using a control (Ex: sqldatasource, objectdatasource, etc..)?
I'm using C#, I cannot find any examples how to use edit, cancel, update, delete feature of the formview without using controls like objectdataSource/sqldataSource? I have 4 buttons (EDIT, SAVE, CANCEL, Delete), not sure how trigger the edit temple, insert template, etc... I would perfer to do it it programmatically. I would be grateful for any help!    if oyu want to change the Current Displayed Tempalte for the FormView , you can call FormView.ChangeMode as  follows:   ' put the FormView in edit mode FormView1.ChangeMode(FormViewMode.Edit)...

Direct editing of gridView or Ddatagrid controls without clicking on an EDIT link
I have an application where lots of data is presented to the user in a gridView control and the user needs the option to review and overwrite any values in the cells of the grid.  My users find it very annoying and time consuming to click on an edit link to turn a row of the gridView into edit mode.  Typically, they might jump around and edit a few values in several rows.  Is there any way to present the data in a gridView control, datagrid control or something that looks like a grid where the entire grid is already in edit mode?  Can you make a grid that cont...

GridView control enters edit mode only when I click Edit link twice
Hi all..I have a GridView control in an ASP.NET 2.0 page. I added a column that contains edit, update, cancel buttons. Because I did that, I had to handle RowEditing event or an exception was thrown.Well... this is the body of the RowEditing event:protected void gvParametros_RowEditing(object sender, GridViewEditEventArgs e){      gvParametros.EditIndex = e.NewEditIndex;}The fact is that when page is loaded and I click the edit link, page is refreshed but GridView doesn't enter edit mode. When I press edit link again, GridView enters edit mode.Any help to solve this behavior w...

How can I allow a user without edit permission to access a control which is of type edit?
Hello,I have a module which allows a user with Edit permission to add a new record or update a record in the database.  I would also like to be able to allow user's without Edit permission to Add and Update records they created.In the view module's "ModuleActions" method I can add the following action:actions.Add(GetNextActionID(), Localization.GetString(ModuleActionType.AddContent, LocalResourceFile), ModuleActionType.AddContent, "", "", EditUrl(), False, DotNetNuke.Security.SecurityAccessLevel.View, True, False) This allows the user's without Edit permission to see the "Add Recor...

Gridview Edit go to new page and enter Edit mode on a formview control.
Okay, so far I have the edit button go to a page called update.aspx. And have the ID selected. However, I don't want it to be in selected view, I want it to go to the update.aspx page in edit mode not selected mode. Is this possible? You can add one hyperlink and set its path to update.aspx?Id=(selectedId)on update.aspx read Id's value from querystring and do updation - Hardik (Software Developer,Surat,India)Please remember to click "Mark as Answer" on this post if it helped you. You lost me at the "do updation part" so far I have a the EDIT link go to ...

Web resources about - Edit a DataControl (without using Edit Mode) - asp.net.presentation-controls

HyTrust, Intel team to lock down VMware virtual machines
HyTrust, in a partnership with Intel, today said its cloud security software used with VMware-based virtual machines can now ensure those VMs ...

Web Application Firewall
Trustwave's Web Application Firewall helps to protect Web applications from SQL Injection and Cross Site Scripting attacks.

WikiLeaks' Assange Loses Fight to Avoid Extradition to Sweden
Julian Assange lost the fight against extradition to Sweden, making it even more likely the United States will be the next to demand his extradition ...

Information Security - Compliance - Trustwave
Trustwave is the leading provider of on-demand and subscription-based information security and PCI DSS compliance management solutions to businesses ...

Contact - HyTrust Contact - HyTrust
Contact (844) 681-8100 Type and hit Enter. Home Solutions Compliance PCI-DSS HIPAA FedRAMP CJIS Private Cloud Controls NSX ESXi VCE –Vblock Ready ...

HyTrust Claims Advances In Virtual Data Center Ops - InformationWeek
VMware security partner HyTrust has been pushing new steps in virtual machine and virtual network operations, including role-based access.

Information Security - Compliance - Trustwave
Trustwave is the leading provider of on-demand and subscription-based information security and PCI DSS compliance management solutions to businesses ...

VMware Virtual SAN 6.0: Data Encryption with Hytrust DataControl
Customers from different industries and institutions are very interested in Virtual SAN as a storage solution not just because of the technological ...

8 Ajax Data Controls and Effects to Work with Tables
Hi fellow reader, I browsed various projects that deals with HTML tables and data control. These a neat to achieve spreadsheet like experience ...

Cloud security investments spike prior to RSA Conference 2015
With RSA Conference 2015 just around the corner, cloud security investments have surged, thanks to big interest from venture capital firms.

Resources last updated: 12/4/2015 11:27:51 AM