C# Gridview:同一行单元格中的多个控件
我在同一个gridview单元格中有许多控件。我正在使用以下代码。但是我希望它们垂直显示,而不是水平显示,因为下面的代码将它们分配在同一行中。有什么帮助吗C# Gridview:同一行单元格中的多个控件,c#,gridview,C#,Gridview,我在同一个gridview单元格中有许多控件。我正在使用以下代码。但是我希望它们垂直显示,而不是水平显示,因为下面的代码将它们分配在同一行中。有什么帮助吗 RadioButton rd1 = new RadioButton(); rd1.Text = "Test1"; RadioButton rd2 = new RadioButton(); rd2.Text = "Test2"; grdRSM.Rows[0].Cells[2].Controls.Add(rd1); grdRSM.Rows[0].
RadioButton rd1 = new RadioButton();
rd1.Text = "Test1";
RadioButton rd2 = new RadioButton();
rd2.Text = "Test2";
grdRSM.Rows[0].Cells[2].Controls.Add(rd1);
grdRSM.Rows[0].Cells[2].Controls.Add(rd2);
从不同的行,你的意思是不同的行??。然后请替换最后一行代码来尝试此操作
grdRSM.Rows[1].Cells[2].Controls.Add(rd2);
你可以做两件事
首先
使用RadioButtonList
而不是单个RadioButton
,并将其设置为RepeatDirection=“Vertical”
秒
使用HtmlGenericControl
渲染BR
类似的内容
RadioButton rd1 = new RadioButton();
rd1.Text = "Test1";
RadioButton rd2 = new RadioButton();
rd2.Text = "Test2";
HtmlGenericControl br = new HtmlGenericControl("BR");
grdRSM.Rows[0].Cells[2].Controls.Add(rd1);
grdRSM.Rows[0].Cells[2].Controls.Add(br);
grdRSM.Rows[0].Cells[2].Controls.Add(rd2);
这将使那些
单选按钮
垂直呈现您需要的内容不清楚。请用上面的代码提供更多细节,它将我的单选按钮添加到同一单元格和同一行。但我希望单选按钮以不同的“行”显示