<form id="form1" runat="server">
<div>
<asp:Wizard ID="Wizard1" runat="server" OnNextButtonClick="Wizard1_NextButtonClick" ActiveStepIndex="0">
<WizardSteps>
<asp:WizardStep runat="server" title="Step 1">
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" DataSourceID="SqlDataSource1" ShowFooter="True" >
<%--Gridview with it assigned sql Data-source--%>
<Columns> <%--Between this tags goes the columns of the gridview--%>
<asp:TemplateField HeaderText="Task_temp_name" SortExpression="Task_temp_name">
<EditItemTemplate> <%--Edit template is what will appear when you are editing the that field of the gridview--%>
<asp:TextBox ID="TextBox1" runat="server" Text='<%# Bind("Task_temp_name") %>'></asp:TextBox> <%--in this case a texbox which will edit the info in the column Task_tempname--%>
</EditItemTemplate>
<ItemTemplate> <%--Item template is the value which is displayed in the field of the gridview--%>
<asp:Label ID="Label1" runat="server" Text='<%# Bind("Task_temp_name") %>'></asp:Label> <%--a label in this case--%>
</ItemTemplate>
<FooterTemplate> <%--We use this footer template to insert data into the gridview by writting in a texbox and clicking a button--%>
<asp:LinkButton ID="CreateButton" runat="server" OnClick="CreateButton_Click">Add New Task</asp:LinkButton> <%--this button adds what we write on the texbox to a new row in the DB--%>
<asp:TextBox ID="AddText" runat="server"></asp:TextBox> <%--the button has his logic in the c# side in the event onclick= CreateButton_Click--%>
</FooterTemplate>
</asp:TemplateField>
<asp:TemplateField>
<EditItemTemplate> <%--the field for the checkbox to select the items we want--%>
<asp:CheckBox ID="CheckBox1" runat="server" />
</EditItemTemplate>
<ItemTemplate>
<asp:CheckBox ID="CheckBox1" runat="server" />
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
<%--Here we see the SqlDatasource which is attached to the previous gridview--%>
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:ConnectionString %>"
SelectCommand="SELECT [Task_temp_name] FROM [Task_templates]" OldValuesParameterFormatString="original_{0}">
</asp:SqlDataSource>
</asp:WizardStep>
<asp:WizardStep runat="server" title="Step 2">
<%--In this gridview we have no Datasource because we want it to be populated according to the values selected on gridview1--%>
<asp:GridView ID="GridView2" runat="server" AutoGenerateColumns="True">
<Columns>
</Columns>
</asp:GridView>
</asp:WizardStep>
</WizardSteps>
</asp:Wizard>
<br />
</div>
</form>
`
// C#HERE
protected void Page_Load(object sender, EventArgs e)
{
LinkButton AddButton = new LinkButton(); //Creation of the button on the footer to add new task_Templates YOU CAN IGNORE THAT
AddButton.Click += new EventHandler(CreateButton_Click); //creation how the eventhandler to handle the behaviour of that button
}
protected void CreateButton_Click(object sender, EventArgs e) //event handler where the text inside the texbox is added as a new row in the database
{
SqlDataSource1.InsertParameters["Task_temp_name"].DefaultValue = ((TextBox)GridView1.FooterRow.FindControl("AddText")).Text;
SqlDataSource1.Insert();
}
protected void Wizard1_NextButtonClick(object sender, WizardNavigationEventArgs e) //eventhandler for the next button click on the wizard when we want to retrieve the selected values
//and store them into the database
{
DataTable dt = new DataTable();
dt.Columns.AddRange(new DataColumn[1] { new DataColumn("Task_name") });
foreach (GridViewRow row in GridView1.Rows)
{
if (row.RowType == DataControlRowType.DataRow)
{
CheckBox chkRow = (row.Cells[1].FindControl("CheckBox1") as CheckBox);
if (chkRow.Checked)
{
string task_temp_name = (row.Cells[0].FindControl("Label1") as Label).Text;
dt.Rows.Add(task_temp_name);
}
}
}
using (SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString))
{
con.Open();
GridView2.DataSource = dt;
GridView2.DataBind(); // I THINK EVERYTHING IS FINE UNTIL HERE
string Task_name = string.Empty;
foreach (GridViewRow GVRow in GridView1.Rows)
{
Task_name = GVRow.Cells[1].Text;
string sqlcmd = @"insert into Tasks (Task_name) values (@Task_temp_name)";
SqlCommand cmd = new SqlCommand(sqlcmd, con);
cmd.CommandText = sqlcmd;
cmd.Parameters.AddWithValue("@Task_temp_name", Task_name.ToString());
cmd.ExecuteNonQuery();
}
}
}