Вопрос

I have a detailsview where I get couple of data from membership profile and I display it on detailsview...this works fine:

 <ItemTemplate>
                <asp:label ID="FirstName" runat="server" />
 </ItemTemplate>

But when I click the edit button, nothing shows up on the field. This is what I am doing on Edit template:

I call ItemUpdating like this:

    protected void DetailsView1_ItemUpdating(Object sender, DetailsViewUpdateEventArgs e)
    {
        //I get my memberprofle here
        MemberProfile memberp = MemberProfile.GetuserProfile(data);
        MembershipUser myuser = Membership.GetUser()

        Label labelfName = DetailsView1.FindControl("FirstName") as Label;
        labelfName.Text = memberp.fName;
    }

Should I be using Itemupdated instead? Or is there another method that I should call when the edit button is clicked that will populate the firstname field on edit? Also, the reason I am keeping it as "LABEL"(usually it would be textbox) on edit mode is that this field has to be read only.

Это было полезно?

Решение

The event ItemUpdating is not fired when you enter on edit mode. You must use DataBound event to set properly required text value.

If neccesary, you can ask CurrentMode property of DetailsView to know if you are editing or displaying.

The result looks like this:

protected void DetailsView1_DataBound(object sender, EventArgs e)
{
    Label l = DetailsView1.FindControl("FirstName") as Label;
    if (DetailsView1.CurrentMode == DetailsViewMode.Edit)
    {
        //obtained from your sample
        MemberProfile memberp = MemberProfile.GetuserProfile(data);
        MembershipUser myuser = Membership.GetUser()

        l.Text = memberp.fName;
    }
    else
    { 
        l.Text = "Another text or nothing";
    }
 }

Be sure to define DataBound event in you Detailsview1 control.

REMARK: It can be affected depending the data bind mode. If so, let me know and put an example.

Другие советы

Add RowUpdating and RowEditing event to your gridview.

http://www.aspdotnet-suresh.com/2011/02/how-to-inserteditupdate-and-delete-data.html

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top