protected void btnColorSubmit_Click(object sender, EventArgs e) { try { if (ViewState["NewColorsCouter"] != null && tvCats.SelectedValue != null) { using (CatalogDataContext dct = new CatalogDataContext()) { int counter = int.Parse(ViewState["NewColorsCouter"].ToString()); for (int i = 0; i < counter; i++) { Label lbl = (Label)this.Master.FindControl("MainContent").FindControl("lblColor" + i); DropDownList ddl = (DropDownList)this.Master.FindControl("MainContent").FindControl("ddlColor" + i); Mapping_Color mColor = new Mapping_Color() { id = System.Guid.NewGuid(), ss_color = lbl.Text, tb_color = ddl.SelectedItem.Text, tb_vid = long.Parse(ddl.SelectedItem.Value), tb_cid = long.Parse(tvCats.SelectedValue) }; dct.Mapping_Colors.InsertOnSubmit(mColor); } dct.SubmitChanges(); } } else throw new ArgumentNullException("ViewState中没有NewColorsCounter"); } catch (Exception ex) { string message = ex.Message.Replace("\n", "\\n").Replace("\r", "").Replace("'", "\\'"); ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "alertMessage", "alert('" + message + "')", true); } }
partial void UpdateMapping_Color(Mapping_Color instance);
partial void DeleteMapping_Color(Mapping_Color instance);
partial void InsertMapping_Color(Mapping_Color instance);