Mam nazwę kolumny tabeli o nazwie QUESTIONTEXTgdzie w tej kolumnie znajdują się 3 pytania. więc są 3 wiersze pytań. Dodaję te pytania do pierwszej kolumny, która działa jak urok. Teraz chcę dodać pole tekstowe lub pole wyboru lub przycisk radiowy obok niego w tej samej komórce lub do następnej kolumny w tym samym rzędzie.
Mam 1 pytanie
1: Jak dodać kontrolkę do tego samego wiersza co tekst, który obecnie dodam, lub do następnej kolumny w tym samym wierszu w tabeli ?.
SCENARIUSZ: W tej samej tabeli mam kolumnę QUESTIONTEXT, a także kolumnę TYPEID z danymi liczbowymi. Albo 1 albo 2
Chodzi o to, że będę wiedział, jaką kontrolę wygenerować dla tego konkretnego pytania według numeru TYPEID
1 dla tekstu
2 dla pola wyboru
Mogę pobrać taki numer:
if (dataRow["TYPEID"].ToString() == "1")
Tak więc, dla pierwszego jest to 1 i chcę dodać pole tekstowe. Muszę tylko wygenerować pole tekstowe lub pole wyboru.
Oto, w jaki sposób obecnie dodaję pytania do pierwszej kolumny w tabeli.
TableRow tableRow;
TableCell tableCell;
foreach (DataTable dataTable in ds.Tables)
{
foreach (DataRow dataRow in dataTable.Rows)
{
tableRow = new TableRow();
tableCell = new TableCell();
TableRow tableRow2 = new TableRow();
TableCell tableCel2 = new TableCell();
tableCell.Text = dataRow["QUESTIONTEXT"].ToString();
if (dataRow["TYPEID"].ToString() == "1")
tableRow.Cells.Add(tableCell);
myTable.Rows.Add(tableRow);
}
}
Stworzyłem także enum, aby pomóc w tym procesie, ale nie jestem pewien, czy to pomoże!
public enum typeID : byte
{
text = 1,
multiple_choice = 2
};
Czy ktoś nie może pomóc? Proszę!
Odpowiedzi:
4 dla odpowiedzi № 1spróbuj tego, aby dodać drugą kolumnę w tym samym rzędzie
TableRow tableRow;
TableCell tableCell;
TableCell tableCell2;
foreach (DataTable dataTable in ds.Tables)
{
foreach (DataRow dataRow in dataTable.Rows)
{
tableRow = new TableRow();
tableCell = new TableCell();
tableCell.Text = dataRow["QUESTIONTEXT"].ToString();
tableCell2 = new TableCell();
switch (dataRow["TYPEID"].ToString())
{
case "1":
Label lbl = new Label();
lbl.Text = "";
tableCell2.Controls.Add(lbl);
break;
case "2":
CheckBox chk = new CheckBox();
chk.Text = "";
tableCell2.Controls.Add(chk);
break;
}
tableRow.Cells.Add(tableCell);
tableRow.Cells.Add(tableCell2);
myTable.Rows.Add(tableRow);
}
}