Thursday, March 22, 2012

Setting the FormView mode programmatically

Hello,

I have a page "xxList.aspx" which lists all the records in table "Domains" with a "ViewDetails" link which takes the users to a detailed FormView of that specific record - "xxAddEdit.aspx" and they can edit the record there (having Upadte and Cancel) buttons. The First Page "xxList.aspx" also gas a "AddNew" button if the users want to add a new record.

The default mode for my FormView is "Edit" To make that AddNew button work I added the following code on thePage_Load event of "xxAddEdit.aspx"

If

(Not IsPostBack)ThenIf (FormView1.PageCount = 0)Then

FormView1.ChangeMode(FormViewMode.Insert)

EndIfEndIf

Now, it loads the page for inserting a new record. But if I click on the "ViewDetails" link on the first page i.e. xxList.aspx", it doesn't show the record details. Instead it opens up ready to insert a new record.

Please suggest how to tackle this.

Hi friends,

I got this working. Thanks to a post on Google Groups. This is what I did -

Protected

Sub Page_Load(ByVal senderAsObject,ByVal eAs System.EventArgs)HandlesMe.LoadDim sidIf (Not IsPostBack)Then

sid = Request.QueryString(

"Id")If (sid ="")Then

FormView1.DefaultMode = FormViewMode.Insert

Else

FormView1.DefaultMode = FormViewMode.Edit

EndIfEndIfEndSub

But, I have another problem now. Once I am in the insert mode and click the "Insert" button after entering in the values for new record, it throws me an error saying -

>FormView 'FormView1' must be in edit mode to update a record.

I have tried setting the formView mode back to Edit on the insert button's click event. Its like -

Protected

Sub Button3_Click(ByVal senderAsObject,ByVal eAs System.EventArgs)

FormView1.DefaultMode = FormViewMode.Edit

EndSub

But, this doesn't work. Can somebody please help? Thanks.

0 comments:

Post a Comment