2012-10-22 27 views
0

我在同一個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].Cells[2].Controls.Add(rd2); 
+0

你需要什麼就不清楚了。請提供更多詳細信息 – sachin

+0

使用上面的代碼,它將我的單選按鈕添加到同一個單元格和同一'行'中。但我希望單選按鈕出現在不同的'行' – user1292656

回答

2

你可以做兩件事

首先

使用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); 

它將使那些RadioButtons被垂直呈現

0

從不同的行開始,你的意思是不同的行。然後請通過替換您的最後一行代碼來嘗試此操作。

grdRSM.Rows[1].Cells[2].Controls.Add(rd2); 
相關問題