Checkbox coché par défaut via fonction asp c#
ecco
Messages postés
89
Statut
Membre
-
ecco Messages postés 89 Statut Membre -
ecco Messages postés 89 Statut Membre -
Bonjour,
j'ai une fonction en c# qui m'affiche mes checkbox et je voudais en coché certaines par défaut via leur position
mais je ne sais pas comment faire
voici ma fonction
private void loadList()
{
critList cl = new critList(), clModel = null;
TableRow tr;
TableCell tc;
CheckBox cb;
TextBox tb;
string sId;
string sModel = null;
int iModel = -1, j = 0;
// Chargement des données d'un éventuel modèle
if (Request.QueryString["idppmodel"] != null)
{
sModel = Request.QueryString["idppmodel"];
clModel = new critList();
clModel.loadByPP(Int32.Parse(sModel));
if (clModel.count == 0)
sModel = null;
}
cl.loadAll();
for (int i=0; i<cl.count; i++)
{
if (!cl[i].active)
continue;
sId = cl[i].idcrit.ToString();
if (sModel != null)
{
for (iModel=0; iModel<clModel.count; iModel++)
if (clModel[iModel].idcrit == cl[i].idcrit)
break;
if (iModel == clModel.count)
iModel = -1;
}
tr = new TableRow();
tr.CssClass = (j++%2==0) ? "list1Item" : "list1Alt";
// Checkbox
tc = new TableCell();
cb = new CheckBox();
cb.ID = "chk" + sId;
cb.Attributes.Add("onclick", "chk_onclick(" + sId + ", this.checked)");
if (iModel != -1)
cb.Checked = true;
tc.Controls.Add(cb);
// Dangereux
HtmlInputHidden hid = new HtmlInputHidden();
hid.ID = "hidDangerous" + sId;
hid.Value = cl[i].dangerous ? "1" : "0";
tc.Controls.Add(hid);
// Libellé (caché)
hid = new HtmlInputHidden();
hid.ID = "hidCaption" + sId;
hid.Value = cl[i].caption;
tc.Controls.Add(hid);
tr.Cells.Add(tc);
// ID - Libellé
tr.Cells[tr.Cells.Add(new TableCell())].Text = sId;
tr.Cells[1].HorizontalAlign = HorizontalAlign.Right;
tr.Cells[tr.Cells.Add(new TableCell())].Text = cl[i].caption;
// Textbox des mesures de prévention
tc = new TableCell();
tb = new TextBox();
tb.ID = "txtMesPrev" + sId;
tb.Height = 21;
if (iModel != -1)
{
tb.Text = clModel[iModel].mesprev;
//tb.Attributes.Add("style", "visibility: visible;");
}
else
{
tb.Text = cl[i].mesprev;
}
tb.Attributes.Add("style", "visibility: hidden;");
tb.Width = 200;
tb.MaxLength = 500;
tc.Controls.Add(tb);
tr.Cells.Add(tc);
// Textbox EPC/EPI
tc = new TableCell();
tb = new TextBox();
tb.ID = "txtEpcEpi" + sId;
tb.Height = 21;
if (iModel != -1)
{
tb.Text = clModel[iModel].epcepi;
//tb.Attributes.Add("style", "visibility: visible;");
}
else
{
tb.Text = cl[i].epcepi;
}
tb.Attributes.Add("style", "visibility: hidden;");
tb.MaxLength = 500;
tc.Controls.Add(tb);
tr.Cells.Add(tc);
// Textbox Consignes
tc = new TableCell();
tb = new TextBox();
tb.ID = "txtCons" + sId;
tb.Height = 21;
if (iModel != -1)
{
tb.Text = clModel[iModel].cons;
//tb.Attributes.Add("style", "visibility: visible;");
}
else
{
tb.Text = cl[i].cons;
}
tb.Attributes.Add("style", "visibility: hidden;");
tb.MaxLength = 500;
tc.Controls.Add(tb);
tr.Cells.Add(tc);
tableCrit.Rows.Add(tr);
}
}
j'ai une fonction en c# qui m'affiche mes checkbox et je voudais en coché certaines par défaut via leur position
mais je ne sais pas comment faire
voici ma fonction
private void loadList()
{
critList cl = new critList(), clModel = null;
TableRow tr;
TableCell tc;
CheckBox cb;
TextBox tb;
string sId;
string sModel = null;
int iModel = -1, j = 0;
// Chargement des données d'un éventuel modèle
if (Request.QueryString["idppmodel"] != null)
{
sModel = Request.QueryString["idppmodel"];
clModel = new critList();
clModel.loadByPP(Int32.Parse(sModel));
if (clModel.count == 0)
sModel = null;
}
cl.loadAll();
for (int i=0; i<cl.count; i++)
{
if (!cl[i].active)
continue;
sId = cl[i].idcrit.ToString();
if (sModel != null)
{
for (iModel=0; iModel<clModel.count; iModel++)
if (clModel[iModel].idcrit == cl[i].idcrit)
break;
if (iModel == clModel.count)
iModel = -1;
}
tr = new TableRow();
tr.CssClass = (j++%2==0) ? "list1Item" : "list1Alt";
// Checkbox
tc = new TableCell();
cb = new CheckBox();
cb.ID = "chk" + sId;
cb.Attributes.Add("onclick", "chk_onclick(" + sId + ", this.checked)");
if (iModel != -1)
cb.Checked = true;
tc.Controls.Add(cb);
// Dangereux
HtmlInputHidden hid = new HtmlInputHidden();
hid.ID = "hidDangerous" + sId;
hid.Value = cl[i].dangerous ? "1" : "0";
tc.Controls.Add(hid);
// Libellé (caché)
hid = new HtmlInputHidden();
hid.ID = "hidCaption" + sId;
hid.Value = cl[i].caption;
tc.Controls.Add(hid);
tr.Cells.Add(tc);
// ID - Libellé
tr.Cells[tr.Cells.Add(new TableCell())].Text = sId;
tr.Cells[1].HorizontalAlign = HorizontalAlign.Right;
tr.Cells[tr.Cells.Add(new TableCell())].Text = cl[i].caption;
// Textbox des mesures de prévention
tc = new TableCell();
tb = new TextBox();
tb.ID = "txtMesPrev" + sId;
tb.Height = 21;
if (iModel != -1)
{
tb.Text = clModel[iModel].mesprev;
//tb.Attributes.Add("style", "visibility: visible;");
}
else
{
tb.Text = cl[i].mesprev;
}
tb.Attributes.Add("style", "visibility: hidden;");
tb.Width = 200;
tb.MaxLength = 500;
tc.Controls.Add(tb);
tr.Cells.Add(tc);
// Textbox EPC/EPI
tc = new TableCell();
tb = new TextBox();
tb.ID = "txtEpcEpi" + sId;
tb.Height = 21;
if (iModel != -1)
{
tb.Text = clModel[iModel].epcepi;
//tb.Attributes.Add("style", "visibility: visible;");
}
else
{
tb.Text = cl[i].epcepi;
}
tb.Attributes.Add("style", "visibility: hidden;");
tb.MaxLength = 500;
tc.Controls.Add(tb);
tr.Cells.Add(tc);
// Textbox Consignes
tc = new TableCell();
tb = new TextBox();
tb.ID = "txtCons" + sId;
tb.Height = 21;
if (iModel != -1)
{
tb.Text = clModel[iModel].cons;
//tb.Attributes.Add("style", "visibility: visible;");
}
else
{
tb.Text = cl[i].cons;
}
tb.Attributes.Add("style", "visibility: hidden;");
tb.MaxLength = 500;
tc.Controls.Add(tb);
tr.Cells.Add(tc);
tableCrit.Rows.Add(tr);
}
}
A voir également:
- Checkbox coché par défaut via fonction asp c#
- Fonction si et - Guide
- Ouvrir avec par défaut - Guide
- Dns par defaut - Guide
- Google page d'accueil par défaut - Guide
- Windows 11 clic droit afficher plus d'options par défaut - Guide
1 réponse
il suffit juste de faire
if (i==75)
{
cb.Checked = true;
}
mais maintenant j'ai un autre problème c'est de les bloqués
alors j'ai tester cela mais sa me bloque la valeur aussi c'est que celle-ci est cencé s'inscrire dans un fichier excel
mais quand je met enable à faux plus rien ne s'affiche !!
if (i==75)
{
cb.Checked = true;
cb.enable= false;
}
if (i==75)
{
cb.Checked = true;
}
mais maintenant j'ai un autre problème c'est de les bloqués
alors j'ai tester cela mais sa me bloque la valeur aussi c'est que celle-ci est cencé s'inscrire dans un fichier excel
mais quand je met enable à faux plus rien ne s'affiche !!
if (i==75)
{
cb.Checked = true;
cb.enable= false;
}