Link to home
Start Free TrialLog in
Avatar of dodgerfan
dodgerfanFlag for United States of America

asked on

Open form to insert new record.

I have a gridview on a form that displays records. Next to each record is a Edit button. When this button is clicked, another form pops up to allow editing of that record. The form that pops up is another asp.net form with a asp:FormView control on it to display a record. I would like to have another button outside of the gridview that will open up the same popup form to insert a new record. So the popup form needs to open up to blank fields. The formview on that form has the EditItemTemplate, ItemTemplate and InsertItemTemplate on it. By defualt I set it to open up in Edit Mode. How can I get my button to open it in Insert Mode? Thanks.
Avatar of GlobaLevel
GlobaLevel
Flag of United States of America image

If I get what your asking ...you can control this from a method gridview row updating function...

the method looks like this:protected void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e)
{
TextBox txtName = (TextBox)GridView1.Rows[e.RowIndex].FindControl("txtName");



TextBox txtCity = (TextBox)GridView1.Rows[e.RowIndex].FindControl("txtCity");

//Your updation query pass the values like set city=' "+txtCity.Text+" '

GridView1.EditIndex = -1; //converts to normal mode from edit mode
// If having any bind method call here to see the updated rows

BindData();//(in this method write binding datasource to GridView1)


}
Hello, you can use the FormView.DefaultMode property to accomplish that, example:
<asp:FormView ID="FormView1" runat="server" DefaultMode="Insert">
.....
</asp:FormView>

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of Carlos Villegas
Carlos Villegas
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of dodgerfan

ASKER

yv989c:
That looks lke exactly what I'm looking for. I'll ive it a shot tomorrow. Thanks.
Avatar of SAMIR BHOGAYTA
Hello, it is very easy to open the blank form into the click event of any button. You have to use the btn.Attributes.Add("OnClick","Value") through the javascript for open the form in popup window.
Perfect, again. Thanks.
Glad to help