protected void gvPhoneNumbers_OnRowDataBound(object sender, GridViewRowEventArgs e) { msPhoneNumberType pt = (msPhoneNumberType)e.Row.DataItem; if (Page.IsPostBack) { return; // only do this if there's a postback - otherwise, preserve ViewState } switch (e.Row.RowType) { case DataControlRowType.Header: break; case DataControlRowType.Footer: break; case DataControlRowType.DataRow: Label lblPhoneNumberType = (Label)e.Row.FindControl("lblPhoneNumberType"); TextBox tbPhoneNumber = (TextBox)e.Row.FindControl("tbPhoneNumber"); var lRadioButtonMarkup = (Literal)e.Row.FindControl("lRadioButtonMarkup"); lblPhoneNumberType.Text = pt.Name; /* We need to extract the phone number from the underlying MemberSuiteObject * phone numbers are flattened, and they are in the format of <Code>_PhoneNumber * where <Code> is the API Code of the phone number type*/ tbPhoneNumber.Text = linkedOrganization.SafeGetValue <string>(pt.Code + "_PhoneNumber"); /* We have to use a literal for our radio button due to an ASP.NET bug with radiobuttons * in repeater controls * http://www.asp.net/learn/data-access/tutorial-51-cs.aspx-->*/ bool isSelected = linkedOrganization.PreferredPhoneNumberType == pt.ID; lRadioButtonMarkup.Text = string.Format( @"<input type=radio name=PhoneNumberPreferredType " + @"id=RowSelector{0} value='{1}' {2} />", e.Row.RowIndex, pt.ID, isSelected ? "checked" : ""); break; } }
private void bindObjectToPage() { tbName.Text = targetObject.Name; // now, the email tbEmail.Text = targetObject.EmailAddress; tbBillingContactName.Text = targetObject.SafeGetValue <string>("BillingContactName"); tbBillingContactPhoneNumber.Text = targetObject.SafeGetValue <string>("BillingContactPhoneNumber"); // ok, we need to get all of the phone number types List <msPhoneNumberType> phoneNumberTypes = getPhoneNumberTypes(); // now, let's bind them if (phoneNumberTypes.Count > 0) { phPhoneNumbers.Visible = true; gvPhoneNumbers.DataKeyNames = new string[] { "Code" }; gvPhoneNumbers.DataSource = phoneNumberTypes; gvPhoneNumbers.DataBind(); } // ok, same with with the addresses List <msAddressType> addressTypes = getAddressTypes(); if (addressTypes.Count > 0) { phAddresses.Visible = true; rptAddresses.DataSource = addressTypes; rptAddresses.DataBind(); // set the preferred addresss ddlPreferredAddress.DataSource = addressTypes; ddlPreferredAddress.DataTextField = "Name"; ddlPreferredAddress.DataValueField = "ID"; ddlPreferredAddress.DataBind(); ListItem li = ddlPreferredAddress.Items.FindByValue(targetObject.PreferredAddressType); if (li != null) { li.Selected = true; // select the preferred address } } }