void GenerateSurvey(string AnketId, System.Web.UI.WebControls.PlaceHolder plch)
{
var db = new Xrm.XrmDataContext(Microsoft.Xrm.Client.CrmConnection.Parse(Utils.getXrmConnectionString(_PortalBrandHelper.BrandProxy.BrandDedicatedCrmOrgName)));
var AnketSoru = from p in db.new_survey_questions
orderby p.new_rank
select new { p.new_survey_questionid, p.new_question_text, p.new_question_type, p.new_rank, p.new_min_enumerator, p.new_max_enumerator };
HtmlTable tbl = new HtmlTable();
tbl.CellPadding = 2;
tbl.CellSpacing = 3;
HtmlTableRow r = new HtmlTableRow();
HtmlTableCell c = new HtmlTableCell();
c.InnerHtml = "<h3>İMMİB</h3>";
c.ColSpan = 2;
c.Align = "center";
r.Cells.Add(c);
tbl.Border = 1;
tbl.ID = "Survey_Inner";
tbl.Rows.Add(r);
c = new HtmlTableCell();
r = new HtmlTableRow();
c.ColSpan = 2;
c.InnerHtml = "<h4>EĞİTİM DEĞERLENDİRME FORMU</h4>";
c.Align = "center";
r.Cells.Add(c);
tbl.Rows.Add(r);
foreach (var item in AnketSoru)
{
r = new HtmlTableRow();
c = new HtmlTableCell();
c.InnerHtml = item.new_question_text.ToString();
r.Cells.Add(c);
switch (item.new_question_type.ToString())
{
case "2": //FreeText
c = new HtmlTableCell();
TxtFreeText = new TextBox();
TxtFreeText.ID = "Txt_" + item.new_survey_questionid.ToString();
TxtFreeText.TextMode = TextBoxMode.MultiLine;
TxtFreeText.Width = 300;
TxtFreeText.Height = 50;
TxtFreeText.EnableViewState = true;
c.Controls.Add(TxtFreeText);
break;
case "3": //CheckBox
c.ColSpan = 2;
var choises = from c1 in db.new_survey_question_choices
where c1.new_survey_questionid == item.new_survey_questionid
select c1;
ChkSecimler = new CheckBoxList();
ChkSecimler.ID = "Chkl_" + item.new_survey_questionid.ToString();
ChkSecimler.RepeatDirection = RepeatDirection.Horizontal;
ChkSecimler.RepeatColumns = 2;
foreach (var ck in choises)
{
LiSecim = new ListItem();
LiSecim.Text = ck.new_name;
ChkSecimler.Items.Add(LiSecim);
}
c.Controls.Add(ChkSecimler);
break;
case "4": //Enumeration ***RadioButton***
c = new HtmlTableCell();
RdSecimler = new RadioButtonList();
RdSecimler.ID = "Rdl_" + item.new_survey_questionid.ToString();
RdSecimler.RepeatDirection = RepeatDirection.Horizontal;
c.Align = "center";
for (int i = Convert.ToInt32(item.new_min_enumerator); i <= Convert.ToInt32(item.new_max_enumerator); i++)
{
LiSecim = new ListItem();
LiSecim.Text = i.ToString();
RdSecimler.Items.Add(LiSecim);
}
c.Controls.Add(RdSecimler);
break;
default:
break;
}
r.Cells.Add(c);
tbl.Rows.Add(r);
}
plch.Controls.Add(tbl);
}
I want to make that radiobuttons fit in that cell not centered but couldnt able to do it, how can i do it any help?
Simply add Attributes
HtmlTable tbl = new HtmlTable();
tbl.Attributes.Add("class","ClassName");
remove c.Align = "center"; and put these radiobuttons inside table with one row and n cells with width=100% to fit it in the parent cell
Is it possible to have it created inside a particular div?
You could then base all the classes on that div.
So lets say the table appears inside:
<div id="new-table"></div>
You could do your css definitions like this:
#new-table table{ }
#new-table tr{ }
#new-table td{text-align:left;}
Do you have a way of giving a unique class to the div with the radio buttons?
Related
I am creating a tab page entirley programatically from a button press in the root page of a tabbed control. At present all the page initialisation takes place in the button click method. After all the instantiation, data capture from file and so on, I finally want to adjust the column widths in the data grid view, so that all the row data appears without having to have horizontal scroll bars. With the help of all your contributors I have managed to get it all working but the last step. Running at full speed it appears the DataGridView is accessed before the data load from the table is complete as it fails with an exception because the count derived from RegistersGrid.ColumnCount (local variable l) is zero. It all works fine if I step through the code. I am assuming that I need to put a Mutex of some form to wait for the transfer to complete, but I can't work out where that is taking place in order to reset the flag! If someone can point me in the right direction or if there is better more structured way to approach this I would deeply appreciate the help :-)
I have included all the code in the method just in case, I am afraid I date back a long way so if this looks like the awkward child of assembler,pascal and c with a little c# thrown in, my apologies....it's my age :-)
private void AddModuleButton_Click(object sender, EventArgs e)
{
string ModuleID = null;
string ModuleTypeFileNumber = null;
string ModuleType = null;
int TabID = 0;
openFileDialog1.Filter = "Text Files (.txt)|*.txt";
DialogResult result = openFileDialog1.ShowDialog();
if (result == DialogResult.OK)
using (StreamReader reader = new StreamReader(openFileDialog1.FileName))
{
string newline;
if ((newline = reader.ReadLine()) != null)
{
string[] values = newline.Split((char)9);
ModuleTypeFileNumber = values[1];
}
if ((newline = reader.ReadLine()) != null)
{
string[] values = newline.Split();
ModuleID = values[0];
ModuleType = values[1];
}
bool AbsorbLines = true;
while (AbsorbLines && ((newline = reader.ReadLine()) != null))
{
string[] values = newline.Split();
if (values[0] == "Readings") AbsorbLines = false;
}
string[] columnnames = { "Summary", "access", "register", "Module & Name", "Value", "unit", "type", "Res" };
string[] columntypes = { "System.Boolean", "System.String", "System.Int32", "System.String", "System.Int32", "System.String", "System.String", "System.String" };
int[] columnwidth = { 1,2,3,35,10,5,5,5 };
DataTable dt = new DataTable();
for(int i =0; i < columnnames.Length; i++)
{
DataColumn colString = new DataColumn(columnnames[i]);
colString.DataType = System.Type.GetType(columntypes[i]);
dt.Columns.Add(colString);
}
while (ImportTable("Controls", reader.ReadLine(), dt, "RO")) { } // Import the "readings" section
while (ImportTable("Status bits", reader.ReadLine(), dt, "RW")) { } // Import the "controls" section
reader.Close();
registerTables.Add(ModuleID, dt);
// create a new tab page
TabPage page = new TabPage(ModuleID);
InterbusRegisters.TabPages.Add(page);
//
// tabPage1
//
Button ResizeButton = new Button();
Button RemoveButton = new Button();
Label VersionLabel = new Label();
Label SerialNolabel = new Label();
TextBox VersionNoTB = new TextBox();
TextBox SerialNoTB = new TextBox();
DataGridView RegistersGrid = new DataGridView();
//
// Set the properties of the DataGrid.
//
RegistersGrid.AccessibleName = ModuleID + "Grid";
RegistersGrid.Location = new System.Drawing.Point(3,29);
RegistersGrid.Width = page.Width - 6;
RegistersGrid.Height = page.Height - 29;
RegistersGrid.Anchor = (AnchorStyles.Top | AnchorStyles.Left);
RegistersGrid.DataSource = dt;
RegistersGrid.Dock = (DockStyle)2;
//
// RemoveButtonRegistersGrid
//
RemoveButton.BackColor = System.Drawing.Color.Red;
RemoveButton.Location = new System.Drawing.Point(3, 4);
RemoveButton.Name = "RemoveButton";
RemoveButton.Size = new System.Drawing.Size(75, 25);
RemoveButton.TabIndex = 0;
RemoveButton.Text = "Remove";
RemoveButton.UseVisualStyleBackColor = false;
RemoveButton.Click += new System.EventHandler(this.RemoveButton_Click);
//
// ResizeButton
//
ResizeButton.BackColor = System.Drawing.Color.DarkOrange;
ResizeButton.Location = new System.Drawing.Point(81, 4);
ResizeButton.Name = "ResizeButton";
ResizeButton.Size = new System.Drawing.Size(75, 25);
ResizeButton.TabIndex = 6;
ResizeButton.Text = "Resize";
ResizeButton.UseVisualStyleBackColor = false;
ResizeButton.Click += new System.EventHandler(this.ResizeButton_Click);
//
// SerialNolabel
//
SerialNolabel.AutoSize = true;
SerialNolabel.Location = new System.Drawing.Point(159, 10);
SerialNolabel.Name = "SerialNolabel";
SerialNolabel.Size = new System.Drawing.Size(53, 13);
SerialNolabel.TabIndex = 4;
SerialNolabel.Text = "Serial No:";
//
// SerialNoTB
//
SerialNoTB.Location = new System.Drawing.Point(215, 7);
SerialNoTB.Name = "SerialNoTB";
SerialNoTB.Size = new System.Drawing.Size(100, 20);
SerialNoTB.TabIndex = 1;
//
// VersionLabel
//
VersionLabel.AutoSize = true;
VersionLabel.Location = new System.Drawing.Point(318, 10);
VersionLabel.Name = "VersionLabel";
VersionLabel.Size = new System.Drawing.Size(45, 13);
VersionLabel.TabIndex = 5;
VersionLabel.Text = "Version:";
//
// VersionTB
//
VersionNoTB.Location = new System.Drawing.Point(366, 7);
VersionNoTB.Name = "VersionTB";
VersionNoTB.Size = new System.Drawing.Size(100, 20);
VersionNoTB.TabIndex = 2;
page.Controls.Add(ResizeButton);
page.Controls.Add(RemoveButton);
page.Controls.Add(VersionLabel);
page.Controls.Add(VersionNoTB);
page.Controls.Add(SerialNolabel);
page.Controls.Add(SerialNoTB);
page.Controls.Add(RegistersGrid);
page.Location = new System.Drawing.Point(4, 22);
page.Size = new System.Drawing.Size(716, 554);
page.TabIndex = 1;
page.UseVisualStyleBackColor = true;
page.Update(); // the following code fails
int k = dt.Columns.Count;
int l = RegistersGrid.ColumnCount;
for (int j = 0; j <= RegistersGrid.ColumnCount - 1; j++)
RegistersGrid.Columns[j].AutoSizeMode = DataGridViewAutoSizeColumnMode.AllCells;
RegistersGrid.Columns[3].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
//datagrid has calculated it's widths so we can store them
for (int i = 0; i <= RegistersGrid.ColumnCount - 1; i++)
{
int colw = RegistersGrid.Columns[i].Width; //store autosized widths
RegistersGrid.Columns[i].AutoSizeMode = DataGridViewAutoSizeColumnMode.None; //remove autosizing
RegistersGrid.Columns[i].Width = colw; //set width to calculated by autosize
}
}
}
I am making student attendance system. I am creating dynamic control and assigning values from database. Now I want to know how to find desired dynamic control and how I will get value from it.
I don't know how I can find desired control using a foreach loop.
This is my code for creating dynamic controls.
public void genControl(StudentAttendence sta)
{
StudentAttendenceBSLDAL stabd = new StudentAttendenceBSLDAL();
List<string[]> liName = stabd.takStudent(sta);
counts = Convert.ToInt16(stabd.takStudent(sta).Count);
for (int i=0; i< stabd.takStudent(sta).Count;i++)
{
for(int j = 0; j<liName[i].Count();j++)
{
Label lblStudentname = new Label();
Label lblStId = new Label();
lblStId.Name = "lblStId"+i.ToString()+j.ToString();
lblStudentname.Name = "liName"+i.ToString()+j.ToString();
lblStId.AutoSize = true;
lblStudentname.AutoSize = true;
if (j==0)
{
lblStId.Text = liName[i][j].ToString();
}
if(j==1)
{
lblStudentname.Text = liName[i][j].ToString();
}
lblStId.AutoSize = true;
lblStudentname.AutoSize = true;
if (i == 1)
{
lblStId.Location = new Point(41, 229);
lblStudentname.Location = new Point(153, 7);
}
else
{
lblStId.Location = new Point(3, 7 + 20);
lblStudentname.Location = new Point(153, 7 + 20);
}
this.Controls.Add(lblStId);
panel1.Controls.Add(lblStudentname);
}
CheckBox cba = new CheckBox();
cba.Name = "cba" + i.ToString() ;
cba.Text = "A";
cba.AutoSize = true;
CheckBox cbp = new CheckBox();
cbp.Name = i.ToString() ;
cbp.Text = "P";
cbp.AutoSize = true;
CheckBox cbl = new CheckBox();
cbl.Name = "cbl" + i.ToString() ;
cbl.Text = "L";
cbl.AutoSize = true;
if (i == 1)
{
cbp.Location = new Point(590, 3);
cba.Location = new Point(631, 3);
cbl.Location = new Point(670, 3);
}
else
{
cbp.Location = new Point(590, 3 + 23);
cba.Location = new Point(631, 3 + 23);
cbl.Location = new Point(670, 3 + 23);
}
panel1.Controls.Add(cbp);
panel1.Controls.Add(cba);
panel1.Controls.Add(cbl);
}
}
This is button control event in which I am trying to find control and get it value.
private void button2_Click(object sender, EventArgs e)
{
StudentAttendence sta = new StudentAttendence();
StudentAttendenceBSLDAL stabd = new StudentAttendenceBSLDAL();
// List<string[]> liName = stabd.takStudent(sta);
for (int i=0;i<counts;i++)
{
CheckBox cbP = panel1.Controls.OfType<CheckBox>().FirstOrDefault(b => b.Name.Equals("cbp"+i.ToString()));
// Label stid = panel1.Controls.Find("lblStId" + i.ToString(), false).First() as Label;
if(!cbP.IsChecked)
{
MessageBox.Show("control found");
}
}
}
You can save your control list into a SortedList.
You can use this sorted list for further processing
i've been trying to create a Table Layout with 2 buttons next to eachother. i've been reading around, however i can't seem te get it to show anything on the screen. this is my current code for the TableLayout.
TableLayout ll = FindViewById<TableLayout>(Resource.Id.buttonLayout);
TableLayout llInner = new TableLayout(this);
TableLayout.LayoutParams lp = new TableLayout.LayoutParams(LinearLayout.LayoutParams.FillParent, LinearLayout.LayoutParams.WrapContent);
llInner.Orientation = Orientation.Horizontal;
llInner.LayoutParameters = lp;
llInner.WeightSum = 2;
ll.AddView(llInner);
var i = 0;
var row = new TableRow(this);
//TableRow.LayoutParams rowlayout = new TableRow.LayoutParams(TableRow.LayoutParams.MatchParent, TableRow.LayoutParams.WrapContent);
row.LayoutParameters = lp;
foreach (var series1 in series)
{
var b = new Button(this);
b.Text = series1.Series;
//lp = new TableLayout.LayoutParams(1, LinearLayout.LayoutParams.WrapContent);
b.LayoutParameters = lp;
row.AddView(b);
i =+ 1;
if (i > 1)
{
llInner.AddView(row, new TableLayout.LayoutParams(TableLayout.LayoutParams.MatchParent, TableLayout.LayoutParams.WrapContent));
row = new TableRow(this);
row.LayoutParameters = lp;
i = 0;
}
}
any suggestions?
thanks in advance,
Bjorn
i've been trying to create a Table Layout with 2 buttons next to eachother.
Just from your code, besides the original TableLayout named buttonLayout, you created another TableLayout and a TableRow, and then added Button controls into this row, but you never add this row to the view of your TableLayout, and you need to pay attention to the LayoutParams, you used a TableLayout.LayoutParams for all controls, but inside it is the LinearLayout.LayoutParams, that's not right.
Since I don't have your series, I can't really understand what you're doing in foreach, here I just post a sample code:
TableLayout ll = FindViewById<TableLayout>(Resource.Id.buttonLayout);
ll.WeightSum = 2;
ll.Orientation = Orientation.Horizontal;
TableRow row = new TableRow(this);
TableRow.LayoutParams lp = new TableRow.LayoutParams(TableRow.LayoutParams.MatchParent, TableRow.LayoutParams.WrapContent);
row.LayoutParameters = lp;
var b = new Button(this);
b.Text = "Button1";
b.LayoutParameters = new TableRow.LayoutParams(TableRow.LayoutParams.MatchParent, TableRow.LayoutParams.WrapContent);
row.AddView(b);
var bb = new Button(this);
bb.Text = "Button2";
bb.LayoutParameters = new TableRow.LayoutParams(TableRow.LayoutParams.MatchParent, TableRow.LayoutParams.WrapContent);
row.AddView(bb);
ll.AddView(row);
ll.Invalidate();
i was doing allot of stuff that wasn't needed. but my dumbest mistake was the part where i did i =+ 1; instead of i += 1;
this is how my code looks now. its doing wat it needs to do now.
TableLayout ll = FindViewById<TableLayout>(Resource.Id.buttonLayout);
//TableLayout llInner = new TableLayout(this);
TableRow.LayoutParams lp = new TableRow.LayoutParams(LinearLayout.LayoutParams.MatchParent, LinearLayout.LayoutParams.MatchParent);
//ll.Orientation = Orientation.Horizontal;
//ll.LayoutParameters = lp;
//ll.WeightSum = 2;
//ll.AddView(llInner);
var i = 0;
var row = new TableRow(this);
row.WeightSum = 2;
//TableRow.LayoutParams rowlayout = new TableRow.LayoutParams(TableRow.LayoutParams.MatchParent, TableRow.LayoutParams.WrapContent);
//row.LayoutParameters = lp;
foreach (var series1 in series)
{
var b = new Button(this);
b.Text = series1.Series;
lp.Weight = 1;
//lp = new TableLayout.LayoutParams(1, LinearLayout.LayoutParams.WrapContent);
b.LayoutParameters = lp;
row.AddView(b);
i += 1;
if (i > 1)
{
ll.AddView(row, new TableLayout.LayoutParams(TableLayout.LayoutParams.MatchParent, TableLayout.LayoutParams.WrapContent));
row = new TableRow(this);
row.LayoutParameters = lp;
i = 0;
}
allot of stuff is commented because i've been messing around with it for a while now.
I am using Open XML SDK 2.5 to insert Tables in a Word Document. The issue I currently have is with the row height of my table heading. It works fine with normal text direction of Left to Right Top to Bottom LTTB. However as soon as I set the Text Direction to Bottom to Top Left to Right BTLR my heading rows do not adjust to fit the cell contents.
Code Below
void InsertTable(string[,] tableData, int numberOfRows, int numberOfColumns, string locationInDocument, string textDirectionHeadings)
{
using (WordprocessingDocument myDoc = WordprocessingDocument.Open(_newDocument, true))
{
var docPart = myDoc.MainDocumentPart;
var doc = docPart.Document;
var table = new Table();
var tableBorderTop = new TopBorder();
var tableBorderBottom = new BottomBorder();
var tableBorderLeft = new LeftBorder();
var tableBorderRight = new RightBorder();
var tableBorderHorizontal = new InsideHorizontalBorder();
var tableBorderVertical = new InsideVerticalBorder();
var tableProperties = new TableProperties();
var borders = new TableBorders();
// Set Border Styles for Table
tableBorderTop.Val = BorderValues.Single;
tableBorderTop.Size = 6;
tableBorderBottom.Val = BorderValues.Single;
tableBorderBottom.Size = 6;
tableBorderLeft.Val = BorderValues.Single;
tableBorderLeft.Size = 6;
tableBorderRight.Val = BorderValues.Single;
tableBorderRight.Size = 6;
tableBorderHorizontal.Val = BorderValues.Single;
tableBorderHorizontal.Size = 6;
tableBorderVertical.Val = BorderValues.Single;
tableBorderVertical.Size = 6;
// Assign Border Styles to Table Borders
borders.TopBorder = tableBorderTop;
borders.BottomBorder = tableBorderBottom;
borders.LeftBorder = tableBorderLeft;
borders.RightBorder = tableBorderRight;
borders.InsideHorizontalBorder = tableBorderHorizontal;
borders.InsideVerticalBorder = tableBorderVertical;
// Append Border Styles to Table Properties
tableProperties.Append(borders);
// Assign Table Properties to Table
table.Append(tableProperties);
//Adds the Table Headings for each Column
var tableRowHeader = new TableRow();
tableRowHeader.Append(new TableRowHeight() { HeightType = HeightRuleValues.Auto });
for (int i = 0; i < numberOfColumns; i++)
{
var tableCellHeader = new TableCell();
//Assign Font Properties to Run
var runPropHeader = new RunProperties();
runPropHeader.Append(new Bold());
runPropHeader.Append(new Color() { Val = "000000" });
//Create New Run
var runHeader = new Run();
//Assign Font Properties to Run
runHeader.Append(runPropHeader);
var columnHeader = new Text();
//Assign the Pay Rule Name to the Run
columnHeader = new Text(tableData[0, i]);
runHeader.Append(columnHeader);
//Create Properties for Paragraph
var justificationHeader = new Justification();
justificationHeader.Val = JustificationValues.Left;
var paraPropsHeader = new ParagraphProperties(justificationHeader);
SpacingBetweenLines spacing = new SpacingBetweenLines() { Line = "240", LineRule = LineSpacingRuleValues.Auto, Before = "0", After = "0" };
paraPropsHeader.Append(spacing);
var paragraphHeader = new Paragraph();
paragraphHeader.Append(paraPropsHeader);
paragraphHeader.Append(runHeader);
tableCellHeader.Append(paragraphHeader);
var tableCellPropertiesHeader = new TableCellProperties();
var tableCellWidthHeader = new TableCellWidth();
tableCellPropertiesHeader.Append(new Shading() { Val = ShadingPatternValues.Clear, Color = "auto", Fill = "#C0C0C0" });
var textDirectionHeader = new TextDirection();
if (textDirectionHeadings == "BTLR")
{
textDirectionHeader.Val = TextDirectionValues.BottomToTopLeftToRight;
}
if (textDirectionHeadings == "LRTB")
{
textDirectionHeader.Val = TextDirectionValues.LefToRightTopToBottom;
}
tableCellPropertiesHeader.Append(textDirectionHeader);
tableCellWidthHeader.Type = TableWidthUnitValues.Auto;
tableCellPropertiesHeader.Append(tableCellWidthHeader);
tableCellHeader.Append(tableCellPropertiesHeader);
tableRowHeader.Append(tableCellHeader);
}
tableRowHeader.AppendChild(new TableHeader());
table.Append(tableRowHeader);
//Create New Row in Table for Each Record
int r = 1;
for (int a = 0; a < (numberOfRows - 1); a++)
{
var tableRow = new TableRow();
for (int i = 0; i < numberOfColumns; i++)
{
var propertyText = tableData[r, i];
var tableCell = new TableCell();
//Assign Font Properties to Run
var runProp = new RunProperties();
runProp.Append(new Bold());
runProp.Append(new Color() { Val = "000000" });
//Create New Run
var run = new Run();
//Assign Font Properties to Run
run.Append(runProp);
//Assign the text to the Run
var text = new Text(propertyText);
run.Append(text);
//Create Properties for Paragraph
var justification = new Justification();
justification.Val = JustificationValues.Left;
var paraProps = new ParagraphProperties(justification);
var paragraph = new Paragraph();
paragraph.Append(paraProps);
paragraph.Append(run);
tableCell.Append(paragraph);
var tableCellProperties = new TableCellProperties();
var tableCellWidth = new TableCellWidth();
tableCellWidth.Type = TableWidthUnitValues.Auto;
tableCellProperties.Append(tableCellWidth);
tableCell.Append(tableCellProperties);
tableRow.Append(tableCell);
}
r = r + 1;
table.Append(tableRow);
};
var res = from bm in docPart.Document.Body.Descendants<BookmarkStart>()
where bm.Name == locationInDocument
select bm;
var bookmark = res.SingleOrDefault();
var parent = bookmark.Parent; // bookmark's parent element
Paragraph newParagraph = new Paragraph();
parent.InsertAfterSelf(newParagraph);
if (bookmark != null)
{
newParagraph.InsertBeforeSelf(table);
}
}
}
foreach (var item in AnketSoru)
{
r = new HtmlTableRow();
c = new HtmlTableCell();
c.InnerHtml = item.new_question_text.ToString();
r.Cells.Add(c);
switch (item.new_question_type.ToString())
{
case "2": //FreeText
c = new HtmlTableCell();
TxtFreeText = new TextBox();
TxtFreeText.ID = "Txt_" + item.new_survey_questionid.ToString();
TxtFreeText.TextMode = TextBoxMode.MultiLine;
TxtFreeText.Width = 300;
TxtFreeText.Height = 50;
TxtFreeText.EnableViewState = true;
c.Controls.Add(TxtFreeText);
HiddenField txthfield = new HiddenField();
txthfield.Value = item.new_name.ToString();
c.Controls.Add(txthfield);
and
foreach (Control c in plc.Controls)
{
System.Web.UI.HtmlControls.HtmlTable Survey_Inner = (System.Web.UI.HtmlControls.HtmlTable)c.FindControl("Survey_Inner");
foreach (System.Web.UI.HtmlControls.HtmlTableRow r in Survey_Inner.Rows)
{
foreach (Control ctr in r.Cells)
{
foreach (Control ct in ctr.Controls)
{
if (ct.GetType().ToString() == "System.Web.UI.WebControls.TextBox")
{
string freeTxtQues = ?? ;
string TextCevap = ((System.Web.UI.WebControls.TextBox)ct).Text;
string deger = ct.ID.ToString();
Guid QuestionId = new Guid(deger.Substring(4));
SaveAnswers(this._PortalUserHelper.UserProxy.ContactId, EgitimKatilimcisi, QuestionId, TextCevap, freeTxtQues);
}
i tryed
string freeTxtQues = ((System.Web.UI.WebControls.HiddenField)ct).Value;
but returns me error. "InvalidCastException was unhandled by user code."
'System.Web.UI.WebControls.TextBox' türündeki nesne 'System.Web.UI.WebControls.HiddenField' türüne atılamadı.
I'm trying to reach hiddenfields value's and set them to the freeTxtQues value but couldn't able to do it for now. Any help for how can i do that?
Hard to understand your question/problem but I will throw something...
When you create dynamic controls you need to create them on Init event so when ViewState is applied he finds the controls and sets their values. If you are not creating the controls in Init but later, you will found out that the control doesn't have the supposed value!