I would like to know the difference between returning a webcontrol and passing one. I have a webcontrol which is in my aspx code. Like
<asp:TableCell>
<telerik:RadComboBox runat="server" ID="rcbName"></telerik:RadComboBox>
</asp:TableCell>
Then I want to programmatically fill the combobox (shouldn't matter what kind of control it is).
So I had this function that returned a combobox:
private RadComboBox rcb CreateRcbSearchResults(DataSet ds)
{
RadComboBox rcb = new RadComboBox();
foreach (DataRow row in ds.Tables[0].Rows)
rcb.Items.Add(new RadComboBoxItem(row["description"].ToString(), row["id"].ToString()));
return rcb;
}
And then I would set the combobox:
rcbName = CreateRcbSearchResults(ds);
For some reason this doesn't work and it would just give me back an empty combobox (browser side), even though I saw it was filled when debugging.
A colleague looked at it and changed my function to pass the combobox:
private void CreateRcbSearchResults(RadComboBox rcb, DataSet ds)
{
foreach (DataRow row in ds.Tables[0].Rows)
rcb.Items.Add(new RadComboBoxItem(row["description"].ToString(), row["id"].ToString()));
}
Now I do:
CreateRcbSearchResults(rcbName, ds);
And now it works. I would like to know why this is. Can someone tell me?