I have a webgrid and add my columns in code-behind. I also have a WebCombo on my page (in the markup) which I would like to add as an EditorControl to one of my columns.. So my problem is that I need to add this EditorControl in code-behind when I create my columns.
I assume that I should do something like
newColumn = new UltraGridColumn("myKey", "myHeader", ColumnType.Custom, "");
newColumn.EditorControlID = myWebCombo.ID;
Correct? I tried doing this but the webcombo is not attached to the column, instead the WebCombo is just displayed on the page outside the grid. I am not sure that the ID is correct.. I tried using ClientID aswell, but doesn't work neither. Any thoughts on this?
Hello,
I think you need to set the type of the column like this
column.Type = ColumnType.Custom;
Regards,
Rado
I made a mistake in my previous post. The WebCombo is not displayed on the page outside the grid, instead it simply disappears.
Anyway, with Rado's suggestion I changed my code to:
newColumn = new UltraGridColumn();
newColumn.Key = "myKey";
newColumn.Type = ColumnType.Custom;
The result is the same! I am able to populate the column with values but there is no WebCombo control in the cells.
Radoslav, could you send me the sample that you mention?
Please find the attached sample.
Just take a look at the method :
//Create a column
void createColumn() {
//Create a column.
UltraGridColumn col1 = new UltraGridColumn(true);
col1.Header.Caption = "Column with WebCombo";
col1.Key = "r1";
col1.Type = ColumnType.Custom;
col1.EditorControlID = WebCombo1.ID;
//Add column to the collection
UltraWebGrid1.Columns.Add(col1);
}
I am using the same code as you but it doesn't work.. Are you adding the web combo in the page markup? If I would like to add it directly to the grid control in code-behind, how can I do that? I tried the following within the grid control, with no luck:
WebCombo wc = new WebCombo();
this.Controls.Add(wc);
also tried
this.Parent.Controls.Add(wc);
Yes, I am adding the combo in aspx. page first and just get a reference to it in code-behind.
The declaration in aspx of the combo is like this :
<igcmbo:WebCombo ID="WebCombo1" runat="server">
</igcmbo:WebCombo>
Can you try this approach in your side?
And let me know the result.
Thanks for helping out!
I have tried this approach earlier and it works fine, but the case is that I want the web combo to "belong" to the grid control, not the page. Can it be done?
can you attach your markup here please.
Thanks.
i want adding combos into cells but every cell can having different values in column
how ? ..
I finally got it working. I am not sure what made the difference, but I have created a minimal page if anyone is interested:
Mark-up (I've removed the DisplayLayout-element within the grid as it is not relevant in this case):
<html xmlns="http://www.w3.org/1999/xhtml"><head runat="server"> <title></title></head><body> <form id="form1" runat="server"> <div> <uc:TestGrid runat="server" ID="TestGrid"> </uc:TestGrid> </div> </form></body></html>
Code-behind:
public partial class MyClass : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { TestGrid.SetUp(); } } public class TestGrid : UltraWebGrid { public void SetUp() { // create web combo var wc = new WebCombo("webComboID"); this.Page.Form.Controls.Add(wc); // create column var column = new UltraGridColumn(); column.Key = "wc"; column.Header.Caption = "Test"; column.Type = ColumnType.Custom; column.EditorControlID = wc.ID; Columns.Add(column); // add a row so the grid won't be empty var row = new UltraGridRow(); Rows.Add(row); } }
I am kind of stuck here :( Radoslav, do you have any additional ideas I can try out?
Yes, I have just tired it. Now the webcombo actually appears on the page, but not inside the grid control :(
From the grid control I am now creating a webcombo and adding it to the page's form:
this.Page.Form.Controls.Add(myWebCombo);
I use a master page, so I am adding the webcombo to the column this way:
myColumn.EditorControlID = myWebCombo.UniqueID;
Any other ideas?