salve gente, questo è il mio primo approccio con la programmazione asp.net, dopo aver seguito la vostra guida c# e asp.net, ho deciso di fare una prova creando una pagina web in cui data una matrice mi si dice se è a scala.
Modificando leggermente un esempio della vostra guida sono arrivato a questo:
codice:
<html>
<head>
<script language="C#" runat="server">
void Page_Load(Object sender, EventArgs e)
{
}
protected void Button1_Click(object sender, EventArgs e)
{
}
protected void nrighe_SelectedIndexChanged(object sender, EventArgs e)
{
int row = 0;
//genera righe e colonne
int numrows = Convert.ToInt32(nrighe.SelectedItem.Text);
int numcells = Convert.ToInt32(ncolonne.SelectedItem.Text);
for (int j = 0; j < numrows; j++)
{
HtmlTableRow r = new HtmlTableRow();
row++;
for (int i = 0; i < numcells; i++)
{
HtmlTableCell c = new HtmlTableCell();
HtmlInputText val = new HtmlInputText();
string nome = "val" + j.ToString() + i.ToString();
val.ID = nome;
val.Value = "0";
val.Size = 2;
c.Controls.Add(val);
r.Cells.Add(c);
}
Table1.Rows.Add(r);
}
}
protected void ncolonne_SelectedIndexChanged(object sender, EventArgs e)
{
int row = 0;
//genera righe e colonne
int numrows = Convert.ToInt32(nrighe.SelectedItem.Text);
int numcells = Convert.ToInt32(ncolonne.SelectedItem.Text);
for (int j = 0; j < numrows; j++)
{
HtmlTableRow r = new HtmlTableRow();
row++;
for (int i = 0; i < numcells; i++)
{
HtmlTableCell c = new HtmlTableCell();
HtmlInputText val = new HtmlInputText();
string nome = "val" + j.ToString() + i.ToString();
val.ID = nome;
val.Value = "0";
val.Size = 2;
c.Controls.Add(val);
r.Cells.Add(c);
}
Table1.Rows.Add(r);
}
}
</script>
<style type="text/css">
#Select1 {
height: 16px;
}
</style>
</head>
<body>
<h3>Matrici a scala</h3>
<form id="Form1" runat="server">
<table id="Table1" CellPadding=5 cellspacing="0" Border="1" BorderColor="black" runat="server" />
<p style="width: 544px; height: 33px">
Matrice:
<asp:DropDownList id="nrighe" runat="server"
onselectedindexchanged="nrighe_SelectedIndexChanged" >
<asp:ListItem>1</asp:ListItem>
<asp:ListItem>2</asp:ListItem>
<asp:ListItem>3</asp:ListItem>
<asp:ListItem>4</asp:ListItem>
</asp:DropDownList>
x
<asp:DropDownList id="ncolonne" runat="server"
onselectedindexchanged="ncolonne_SelectedIndexChanged" >
<asp:ListItem>1</asp:ListItem>
<asp:ListItem>2</asp:ListItem>
<asp:ListItem>3</asp:ListItem>
<asp:ListItem>4</asp:ListItem>
</asp:DropDownList>
<p style="width: 544px; height: 33px">
<asp:Button ID="Button1" runat="server" onclick="Button1_Click"
Text="E' a scala?" />
</form>
<p style="width: 544px; height: 62px">
<asp:Label ID="testover" runat="server"></asp:Label>
</p>
</body>
</html>
ho capito che il mio codice in c# viene eseguito al caricamento della pagina, quindi quando premo il pulsante, essendo un sender mi richiama la pagina giusto?
Quello che vorrei fare è che la matrice modifichi le sue dimensioni selezionandole dai <select> sfortunatamente però visual studio non mi fa inserire nuovi eventi in c#, solo in javascript.
quello che vorrei fare è rigenerare la nuova matrice al variare delle dimensioni e verificare se è a scala (devo ancora scrivere il codice) quando premo il pulsante, ma non riesco a gestire gli eventi