开发者

c# - Dynamically created table and adjusting TextBox length

开发者 https://www.devze.com 2023-03-16 03:00 出处:网络
In the code below (which is in loop - not shown!), the length of the string contained in TextBox is too long. How can I fix this? Also, is it possible to use a Text开发者_运维百科View instead of a Tex

In the code below (which is in loop - not shown!), the length of the string contained in TextBox is too long. How can I fix this? Also, is it possible to use a Text开发者_运维百科View instead of a TextBox?

TableCell tc = new TableCell();
TextBox txtBox = new TextBox();
txtBox.Text = reader.GetString(col);
// Add the control to the TableCell
tc.Controls.Add(txtBox);
// Add the TableCell to the TableRow
tr.Cells.Add(tc);
col++;


If you would rather have a text, use a Label instead of TextBox. Like that:

TableCell tc = new TableCell();
Label label = new Label();
label.Text = reader.GetString(col);
// Add the control to the TableCell
tc.Controls.Add(label);
// Add the TableCell to the TableRow
tr.Cells.Add(tc);
col++;

Now, if you want to have control over the TextBox width, you can just set it:

txtBox.Width = 40; //or whatever value suits your needs


You can use the label control instead of the textbox, if you just want to display to the user the text and don't want them to edit it.

0

精彩评论

暂无评论...
验证码 换一张
取 消