private static void SetProperty(DataControlField target, string propertyName, object value) { target.GetType().GetProperty(propertyName).SetValue(target, value, null); }
private WebControl GetButton(DataControlField fld, string commandName, string commandArg, int itemIdx, int colIdx, string buttonText, string imgUrl) { ButtonType btnType = ButtonType.Button; if (fld is CommandField) btnType = ((CommandField)fld).ButtonType; else if (fld is ButtonField) btnType = ((ButtonField)fld).ButtonType; else throw new Exception("Unrecognized DataControlField type: " + fld.GetType().Name); switch (btnType) { case ButtonType.Button: { Button btn = new Button(); btn.ID = string.Format("btn{0}_{1}_{2}", commandName, itemIdx, colIdx); btn.Text = buttonText; btn.CommandName = commandName; btn.CommandArgument = commandArg; return btn; } case ButtonType.Link: { LinkButton lnk = new LinkButton(); lnk.ID = string.Format("lnk{0}_{1}_{2}", commandName, itemIdx, colIdx); lnk.Text = buttonText; lnk.CommandName = commandName; lnk.CommandArgument = commandArg; return lnk; } case ButtonType.Image: { ImageButton img = new ImageButton(); img.ID = string.Format("img{0}_{1}_{2}", commandName, itemIdx, colIdx); img.ImageUrl = imgUrl; img.CommandName = commandName; img.CommandArgument = commandArg; return img; } default: throw new Exception("Unrecognized control ButtonType: " + btnType.ToString()); } }