Hi,
I have a FormView which contains a Wizard which contains some databinding controls in its steps like Gridview,FormView,...and their ObjectDataSource controls
I want these controls to perform their insert,update methods only when the Wizard finish button is clicked.Is this possible?
About putting the whole wizard inside a FormView I did this to be able to use Bind+Eval but it is the first time Iam using the wizard control.
![]() |
0 |
![]() |
Hi TheEagle ,
Try something like this :
protected void Page_Load(object sender, EventArgs e) { if (!Page.IsPostBack) { this.Wizard1.ActiveStepIndex = 0; DataSet ds = retrievedata(); this.GridView1.DataSource = ds; GridView1.DataBind(); } } protected void Wizard1_FinishButtonClick(object sender, WizardNavigationEventArgs e) { SelectSqlRows((DataSet)Session["ds"], @"Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\Database2.mdf;Integrated Security=True;User Instance=True", "select * from country", "country"); } public DataSet retrievedata() { DataSet res = new DataSet(); if (Session["ds"] == null) { string constr = @"Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\Database2.mdf;Integrated Security=True;User Instance=True"; SqlConnection con = new SqlConnection(constr); SqlDataAdapter sda = new SqlDataAdapter("select * from country", con); sda.Fill(res, "country"); DataColumn[] primarykey = { res.Tables[0].Columns["countryid"] }; res.Tables[0].PrimaryKey = primarykey; Session["ds"] = res; } else { res = Session["ds"] as DataSet; } return res; } protected void GridView1_RowEditing(object sender, GridViewEditEventArgs e) { this.GridView1.EditIndex = e.NewEditIndex; this.GridView1.DataSource = retrievedata(); GridView1.DataBind(); } protected void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e) { Label id = this.GridView1.Rows[e.RowIndex].FindControl("Label1") as Label; TextBox name = this.GridView1.Rows[e.RowIndex].FindControl("TextBox1") as TextBox; DataSet ds = Session["ds"] as DataSet; DataRow dr = ds.Tables[0].Rows.Find(id.Text); dr["countryname"] = name.Text; Session["ds"] = ds; this.GridView1.DataSource = retrievedata(); this.GridView1.EditIndex = -1; GridView1.DataBind(); } public void SelectSqlRows(DataSet target, string connectionString, string queryString, string tableName) { using (SqlConnection connection = new SqlConnection(connectionString)) { SqlDataAdapter adapter = new SqlDataAdapter(); adapter.SelectCommand = new SqlCommand(queryString, connection); SqlCommandBuilder builder = new SqlCommandBuilder(adapter); connection.Open(); //code to modify data in DataSet here builder.GetUpdateCommand(); //Without the SqlCommandBuilder this line would fail adapter.Update(target, tableName); } }<asp:Wizard ID="Wizard1" runat="server" ActiveStepIndex="0" OnFinishButtonClick="Wizard1_FinishButtonClick"> <WizardSteps> <asp:WizardStep runat="server" Title="Step 1"> <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" DataKeyNames="countryid" Width="339px" OnRowEditing="GridView1_RowEditing" OnRowUpdating="GridView1_RowUpdating"> <Columns> <asp:CommandField ShowEditButton="True" /> <asp:TemplateField HeaderText="countryid" SortExpression="countryid"> <EditItemTemplate> <asp:Label ID="Label1" runat="server" Text='<%# Eval("countryid") %>'></asp:Label> </EditItemTemplate> <ItemTemplate> <asp:Label ID="Label1" runat="server" Text='<%# Bind("countryid") %>'></asp:Label> </ItemTemplate> </asp:TemplateField> <asp:TemplateField HeaderText="countryname" SortExpression="countryname"> <EditItemTemplate> <asp:TextBox ID="TextBox1" runat="server" Text='<%# Bind("countryname") %>'></asp:TextBox> </EditItemTemplate> <ItemTemplate> <asp:Label ID="Label2" runat="server" Text='<%# Bind("countryname") %>'></asp:Label> </ItemTemplate> </asp:TemplateField> </Columns> </asp:GridView> </asp:WizardStep> <asp:WizardStep runat="server" Title="Step 2"> </asp:WizardStep> </WizardSteps> </asp:Wizard>
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 |
![]() |