Jump to content
poliveira1978

Asp:Wizard

Recommended Posts

poliveira1978

Boa noite.

Estou a fazer uma página com um wizard e já consigo preencher os steps com campos da BD. O meu problema é como atribuir code-behind a esses passos se o wizard só existe em runtime.

Em seguida excertos do código:

ASPX

<body>
<form id="form1" runat="server">
<div>
<asp:PlaceHolder ID="PlaceHolder1" runat="server"/>
</div>
</form>
</body>

C#

	protected void Page_Load(object sender, EventArgs e)
	{
	Wizard Wizard1 = new Wizard();
	Wizard1.ID = "Wizard1";
	SqlConnection conn = new SqlConnection(Database.ConnectionString);  //Database.Connection definida numa classe
	conn.Open();
	SqlDataAdapter sda = new SqlDataAdapter("select * from Categorias", conn);
	DataSet ds = new DataSet();
	sda.Fill(ds, "Categorias");
	for (int i = 0; i <= ds.Tables["Categorias"].Rows.Count - 1; i++)
		{
		WizardStepBase newStep = new WizardStep();
		newStep.ID = ds.Tables["Categorias"].Rows[i]["idCategoria"].ToString();
		newStep.Title = ds.Tables["Categorias"].Rows[i]["Categoria"].ToString();
		Label label = new Label();
		Label label2 = new Label();
		label.Text = i+" - Nome: ";
		label.AssociatedControlID = "txtName" + i;
		TextBox textbox = new TextBox();
		textbox.ID = "txtName" + i;
		newStep.Controls.Add(label);
		newStep.Controls.Add(textbox);
		newStep.Controls.Add(label2);
		Wizard1.WizardSteps.Add(newStep);
		}
	PlaceHolder1.Controls.Add(Wizard1);
	}

Agradeço qualquer dica.

Share this post


Link to post
Share on other sites
petvetbr

Você terá que adicionar handlers de eventos dos controles usando o operador+=. Exemplo

button1.Click += button1.Click(.....,.....) Procure por "codebehind event handler"


Fernando Lage Bastos - MCP/MCTS/MCPD

Share this post


Link to post
Share on other sites
poliveira1978

Obrigado, resolveu o problema.

A titulo de curiosidade para localizar os botões em cada passo do wizard utilizei o seguinte código:

Devolve o nome do controlo dentro do Wizard

private Control GetControlFromWizard(Wizard wizard, int passo, string controlName)
	{
	System.Text.StringBuilder strCtrl = new System.Text.StringBuilder();
	if (passo == 1)
		{
		strCtrl.Append("StartNavigationTemplateContainerID");
		}
	else if ((1 < passo) && (passo < 10)) // O meu Wizard tem 10 passos, tenho que melhorar isto de forma a obter a contagem programaticamente
		{
		strCtrl.Append("StepNavigationTemplateContainerID");
		}
	else strCtrl.Append("FinishNavigationTemplateContainerID");
	strCtrl.Append("$");
	strCtrl.Append(controlName);

	return wizard.FindControl(strCtrl.ToString());
	}

Encontrar o botão e definir propriedades

		Button btnStartNext = GetControlFromWizard(Wizard1, 1, "StartNextButton") as Button;
		Button btnStepPrevious = GetControlFromWizard(Wizard1, 2, "StepPreviousButton") as Button;
		Button btnFinishPrevious = GetControlFromWizard(Wizard1, 10, "FinishPreviousButton") as Button;
		Button btnFinish = GetControlFromWizard(Wizard1, 10, "FinishButton") as Button;
		btnStartNext.Click += new EventHandler(btnStartNext_Click);
		btnFinish.Click += new EventHandler(Fim);

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×
×
  • Create New...

Important Information

By using this site you accept our Terms of Use and Privacy Policy. We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.