大家好,我尝试各种方法来解决这个问题而没有解决方案
我在转发器内有下拉列表,按钮用于删除此下拉列表我也在转发器外添加按钮以添加下拉列表问题是我点击按钮我丢失了转发器外的所有cssclass我有cssclass的复选框和它正常工作如果我不& #39; t点击按钮
这是我的代码
<div id="content">
<table id="tableDescription" style="width:65%">
<asp:Repeater ID="Repeater1" runat="server" OnItemCommand="Repeater1_ItemCommand" OnItemDataBound="Repeater1_ItemDataBound" OnDataBinding="Repeater1_DataBinding" OnPreRender="Repeater1_PreRender" >
<ItemTemplate>
<tr>
<td valign="middle" style="width:100%">
<table >
<tr>
<td style="width:100%">
<asp:DropDownList ID="txtDescription" runat="server" CssClass="form-control input-lg m-bot15" Height="45px" Width="87%"> <asp:ListItem Value="0" Text="Select Degree" />
</asp:DropDownList>
</td>
<td style="width:100%;" valign="left">
<asp:Button ID="btnRemove" runat="server" Text="Remove" CssClass="btn btn-danger" ToolTip="Remove this description" Height="45px" />
</td>
</tr>
<tr style="height:20PX;">
<td></td>
</tr>
</table>
</td>
</tr>
</ItemTemplate>
</asp:Repeater>
<tr>
<td align="right">
<asp:Button ID="btnAdd" runat="server" CssClass="btn btn-primary" Text="Add Languge" OnClick="btnAdd_Click" />
</td>
</tr>
</table>
</div>
</td>
<td class="auto-style57"> </td>
<td> </td>
<td class="auto-style56"> </td>
<td> </td>
</tr>
</table>
</div>
</div>
</div></td>
</tr>
<tr>
<td colspan="3"> </td>
</tr>
<tr>
<td colspan="3"> </td>
</tr>
<tr>
<td colspan="3">
<div class="content-body"> <div class="row">
<div class="col-md-12 col-sm-12 col-xs-12">
<table cellspacing="0" class="auto-style7">
<tr>
<td colspan="5">
<asp:Label ID="lblfood" runat="server" Text="Food & drink"></asp:Label>
</td>
</tr>
<tr>
<td>
</td>
<td>
<asp:CheckBox ID="chkRN" runat="server" AutoPostBack="false" CssClass="skin-flat-green"/>
</td>
<td>
<asp:Label ID="lblreturantneer" runat="server" Text="Restaurants near"></asp:Label>
</td>
<td>
<asp:CheckBox ID="chkRD" runat="server" />
</td>
<td>
</td>
<td>
<asp:Label ID="lblGROCERY_DELIVERIES" runat="server" Text="Resturant Deliveries"></asp:Label>
</td>
</tr>
<tr>
<td>
</td>
<td>
<asp:CheckBox ID="chkBBQ" runat="server" />
</td>
<td>
<asp:Label ID="lblBBQ_FACILITIES" runat="server" Text="BBQ Area"></asp:Label>
</td>
<td>
<asp:CheckBox ID="chkDM" runat="server" />
</td>
<td>
</td>
<td>
<asp:Label ID="lblVENDING_MACHINE_DRINKS" runat="server" Text="Drinks Machine"></asp:Label>
</td>
</tr>
<tr>
<td>
</td>
<td>
<asp:CheckBox ID="chkMS" runat="server" />
</td>
<td>
<asp:Label ID="lblVENDING_MACHINE_SNACKS" runat="server" Text="Snack Machine"></asp:Label>
</td>
<td>
<asp:CheckBox ID="chkBuffet" runat="server" />
</td>
<td>
</td>
<td style="margin-left: 40px">
<asp:Label ID="lblBUFFET_STYLE_RESTAURANT" runat="server" Text="BUFFET"></asp:Label>
</td>
</tr>
<tr>
<td>
</td>
<td>
<asp:CheckBox ID="chkSnack" runat="server" />
</td>
<td>
<asp:Label ID="lblSNACK_BAR" runat="server" Text="Snack"></asp:Label>
</td>
<td> </td>
<td> </td>
<td> </td>
</tr>
</table>
</div></div>
</td>
</tr>
protected void Page_Load(object sender, EventArgs e)
{
chkfee.InputAttributes["class"] = "iswitch iswitch-md iswitch-primary";
chkactiv.InputAttributes["class"] = "iswitch iswitch-md iswitch-primary";
chkownercontact.InputAttributes["class"] = "iswitch iswitch-md iswitch-primary";
myTable.Columns.Add("degreeCode");
DateTable.Columns.Add("DateFrom");
DateTable.Columns.Add("DateTo");
DateTable.Columns.Add("DatePrice");
{
#region food
chkRN.InputAttributes["class"] = "skin-flat-green";
chkBBQ.InputAttributes["class"] = "skin-flat-green";
chkSnack.InputAttributes["class"] = "skin-flat-green";
chkMS.InputAttributes["class"] = "skin-flat-green";
chkRD.InputAttributes["class"] = "skin-flat-green";
chkDM.InputAttributes["class"] = "skin-flat-green";
chkBuffet.InputAttributes["class"] = "skin-flat-green";
#endregion
#region activities
chkTeenis.InputAttributes["class"] = "skin-flat-green";
chkBilliards.InputAttributes["class"] = "skin-flat-green";
chkTableTeenis.InputAttributes["class"] = "skin-flat-green";
chkSquash.InputAttributes["class"] = "skin-flat-green";
chkBowling.InputAttributes["class"] = "skin-flat-green";
chkMG.InputAttributes["class"] = "skin-flat-green";
ChkWS.InputAttributes["class"] = "skin-flat-green";
chkGolf.InputAttributes["class"] = "skin-flat-green";
chkwindsurfing.InputAttributes["class"] = "skin-flat-green";
chkDiving.InputAttributes["class"] = "skin-flat-green";
chkFishing.InputAttributes["class"] = "skin-flat-green";
chkHR.InputAttributes["class"] = "skin-flat-green";
chkcycling.InputAttributes["class"] = "skin-flat-green";
chkWD.InputAttributes["class"] = "skin-flat-green";
chkSelling.InputAttributes["class"] = "skin-flat-green";
chkVB.InputAttributes["class"] = "skin-flat-green";
chkFB.InputAttributes["class"] = "skin-flat-green";
chkGDB.InputAttributes["class"] = "skin-flat-green";
#endregion
#region Pool
chkINpool.InputAttributes["class"] = "skin-flat-green";
chkPS.InputAttributes["class"] = "skin-flat-green";
chkIPAY.InputAttributes["class"] = "skin-flat-green";
chkOutPool.InputAttributes["class"] = "skin-flat-green";
chkOutPAY.InputAttributes["class"] = "skin-flat-green";
chkBA.InputAttributes["class"] = "skin-flat-green";
chkBechfront.InputAttributes["class"] = "skin-flat-green";
chkSpa.InputAttributes["class"] = "skin-flat-green";
chkSuna.InputAttributes["class"] = "skin-flat-green";
chkTB.InputAttributes["class"] = "skin-flat-green";
chkHT.InputAttributes["class"] = "skin-flat-green";
chkFC.InputAttributes["class"] = "skin-flat-green";
chksolarium.InputAttributes["class"] = "skin-flat-green";
chkMassage.InputAttributes["class"] = "skin-flat-green";
chkOPS.InputAttributes["class"] = "skin-flat-green";
chkKP.InputAttributes["class"] = "skin-flat-green";
#endregion
#region Misc
chkadult.InputAttributes["class"] = "skin-flat-green";
chkDSA.InputAttributes["class"] = "skin-flat-green";
chkheating.InputAttributes["class"] = "skin-flat-green";
chkGR.InputAttributes["class"] = "skin-flat-green";
chkPG.InputAttributes["class"] = "skin-flat-green";
chkCS.InputAttributes["class"] = "skin-flat-green";
chkhearth.InputAttributes["class"] = "skin-flat-green";
chksingles.InputAttributes["class"] = "skin-flat-green";
chkPets.InputAttributes["class"] = "skin-flat-green";
chkAllNS.InputAttributes["class"] = "skin-flat-green";
chkAirCond.InputAttributes["class"] = "skin-flat-green";
chkGrean.InputAttributes["class"] = "skin-flat-green";
chkKidesarea.InputAttributes["class"] = "skin-flat-green";
chkMN.InputAttributes["class"] = "skin-flat-green";
chkBShar.InputAttributes["class"] = "skin-flat-green";
chkFO.InputAttributes["class"] = "skin-flat-green";
chkSinglFamily.InputAttributes["class"] = "skin-flat-green";
chktree.InputAttributes["class"] = "skin-flat-green";
#endregion
#region paymethod
chkvisa.InputAttributes["class"] = "skin-flat-green";
chkvisa.CssClass = "skin-flat-green";
chkmastercard.InputAttributes["class"] = "skin-flat-green";
chksadad.InputAttributes["class"] = "skin-flat-green";
chkpayatplace.InputAttributes["class"] = "skin-flat-green";
#endregion
BindImages();
}
if (!IsPostBack)
{
txtDateFromPrice.CssClass = "form-control datepicker col-md-4";
DataTable ImgTable = new DataTable();
DataRow dr;
ImgTable.Columns.Add("PROPERTY_IMAG_ID");
ImgTable.Columns.Add("PROPERTY_IMAG");
ImgTable.Columns.Add("PROPERTY_PROPERTY_IMAG_PROP_ID");
ImgTable.Columns.Add("PROPERTY_IMAG_SIZE");
ImgTable.Columns.Add("PROPERTY_IMAG_TYPE");
dr = ImgTable.NewRow();
ImgTable.Rows.Add(dr);
ViewState["ImgTablestate"] = ImgTable;
myTable = (DataTable)ViewState["myTablestate"];
DLCountry.DataSource = GH.GetCountries();
DLCountry.DataTextField = "EnglishName";
DLCountry.DataValueField = "id";
DLCountry.DataBind();
DLGroup.DataSource = OH.GetOwnerGroup();
DLGroup.DataTextField = "OWNER_GROUPE_TYPE";
DLGroup.DataValueField = "OWNER_GROUPE_ID";
DLGroup.DataBind();
dt = prop.GetNextIDProperty();
dtfile = IH.GetNextIDIMAGES();
HIDFOLDERID.Value = dt.Rows[0][0].ToString();
HiddenFILEID.Value = HiddenFILEID.Value = Convert.ToString(Convert.ToInt64(HIDFOLDERID.Value + "1406") + 1);
BindImages();
Bind();
BindRepetDate();
DLLanguge.DataSource = GH.GetCountries();
DLLanguge.DataTextField = "EnglishName";
DLLanguge.DataValueField = "id";
DLLanguge.Items.Insert(0, new ListItem("---Select---", "0"));
DLLanguge.DataBind();
}
}
protected void NewRegistrationButton_Click(object sender, EventArgs e)
{
}
protected void Bind()
{
Repeater1.DataSource = myTable;
Repeater1.DataBind();
}
////////
[WebMethod]
public void BindImages()
{
// GridImag.DataSource = ImgTable;
GridImag.DataBind();
GridImag.SelectedIndex = -1;
}
public static bool DeleteFile(string filePath)
{
try
{
if (File.Exists(HttpContext.Current.Server.MapPath(filePath)))
{
File.Delete(HttpContext.Current.Server.MapPath(filePath));
return true;
}
return false;
}
catch
{
return false;
}
}
protected void btnUpload_Click(object sender, EventArgs e)
{
Random rand = new Random();
long img_id=rand.Next();
dt = prop.GetNextIDProperty();
HIDFOLDERID.Value = dt.Rows[0][0].ToString();
HiddenFILEID.Value = Convert.ToString(img_id);
// ImgTable = (DataTable)ViewState["ImgTable"];
string type,size;
if (txtImage.UploadedFiles.Count > 0)
{
if (IH.CheckAndCreateFolder(HIDFOLDERID.Value) == true)
{
foreach (var file in from UploadedFile file in txtImage.UploadedFiles select file)
{
type = Path.GetExtension(file.FileName).ToLower();
var filePath = string.Format("/properties_images/" + HIDFOLDERID.Value + "/{0}"+type, HiddenFILEID.Value);
type = Path.GetExtension(filePath).ToLower();
string fileSize = file.ContentLength.ToString();
file.SaveAs(Server.MapPath(filePath));
if (ViewState["ImgTablestate"] != null)
{
//get datatable from view state
DataTable ImgTable1 = (DataTable)ViewState["ImgTablestate"];
DataRow ImgTablerow = ImgTable1.NewRow();
if (ImgTable1.Rows.Count > 0)
{
for (int i = 1; i <= ImgTable1.Rows.Count; i++)
{
//add each row into data table
ImgTablerow["PROPERTY_IMAG_ID"] = HiddenFILEID.Value;
ImgTablerow["PROPERTY_IMAG"] = filePath;
ImgTablerow["PROPERTY_PROPERTY_IMAG_PROP_ID"] = HIDFOLDERID.Value;
ImgTablerow["PROPERTY_IMAG_SIZE"] = fileSize;
ImgTablerow["PROPERTY_IMAG_TYPE"] = type;
}
//Remove initial blank row
if (ImgTable1.Rows[0][0].ToString() == "")
{
ImgTable1.Rows[0].Delete();
ImgTable1.AcceptChanges();
}
//add created Rows into dataTable
ImgTable1.Rows.Add(ImgTablerow);
//Save Data table into view state after creating each row
ViewState["ImgTablestate"] = ImgTable1;
//Bind Gridview with latest Row
GridImag.DataSource = ImgTable1;
GridImag.DataBind();
GridImag.SelectedIndex = -1;
}
}
}
}
else
{
foreach (var file in from UploadedFile file in txtImage.UploadedFiles select file)
{
type = Path.GetExtension(file.FileName).ToLower();
var filePath = string.Format("/properties_images/" + HIDFOLDERID.Value + "/{0}" + type, HiddenFILEID.Value);
string fileSize = file.ContentLength.ToString();
file.SaveAs(Server.MapPath(filePath));
//IH.insertImages(Convert.ToInt64(HIDFOLDERID.Value), filePath, fileSize, type);
if (ViewState["ImgTablestate"] != null)
{
//get datatable from view state
DataTable ImgTable1 = (DataTable)ViewState["ImgTablestate"];
DataRow ImgTablerow = ImgTable1.NewRow();
if (ImgTable1.Rows.Count > 0)
{
for (int i = 1; i <= ImgTable1.Rows.Count; i++)
{
//add each row into data table
ImgTablerow["PROPERTY_IMAG_ID"] = HiddenFILEID.Value;
ImgTablerow["PROPERTY_IMAG"] = filePath;
ImgTablerow["PROPERTY_PROPERTY_IMAG_PROP_ID"] = HIDFOLDERID.Value;
ImgTablerow["PROPERTY_IMAG_SIZE"] = fileSize;
ImgTablerow["PROPERTY_IMAG_TYPE"] = type;
}
//Remove initial blank row
if (ImgTable1.Rows[0][0].ToString() == "")
{
ImgTable1.Rows[0].Delete();
ImgTable1.AcceptChanges();
}
//add created Rows into dataTable
ImgTable1.Rows.Add(ImgTablerow);
//Save Data table into view state after creating each row
ViewState["ImgTablestate"] = ImgTable1;
//Bind Gridview with latest Row
GridImag.DataSource = ImgTable1;
GridImag.DataBind();
GridImag.SelectedIndex = -1;
}
}
}
}
}
}
protected void GridImag_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
GridImag.PageIndex = e.NewPageIndex;
BindImages();
}
protected void GridImag_PreRender(object sender, EventArgs e)
{
if (GridImag.Rows.Count == 0)
{
// Do Something
}
else
{
GridImag.UseAccessibleHeader = true;
GridImag.HeaderRow.TableSection = TableRowSection.TableHeader;
}
}
protected void GridImag_SelectedIndexChanged(object sender, EventArgs e)
{
}
protected void DeleteImagesClick(object sender, EventArgs e)
{
var filePath = HDurl.Value.ToString();
string check = WHois.Value.ToString();
if (check == "I")
{
long imgid = Convert.ToInt64(hiddenF.Value);
//IH.DeleteImages(imgid);
DeleteFile(filePath);
DataTable ImgTable1 = (DataTable)ViewState["ImgTablestate"];
for (int i = 0; i < ImgTable1.Rows.Count; i++)
{
if (ImgTable1.Rows[i]["PROPERTY_IMAG_ID"].ToString() == hiddenF.Value)
{
ImgTable1.Rows.RemoveAt(i);
}
}
GridImag.DataSource = ImgTable1;
GridImag.DataBind();
GridImag.SelectedIndex = -1;
}
}
protected void PopulateDataTable()
{
foreach (RepeaterItem item in Repeater1.Items)
{
DropDownList txtDescription = (DropDownList)item.FindControl("txtDescription");
DataRow row = myTable.NewRow();
row["degreeCode"] = txtDescription.SelectedValue.ToString();
myTable.Rows.Add(row);
}
}
protected void Repeater1_ItemCommand(object source, RepeaterCommandEventArgs e)
{
PopulateDataTable();
myTable.Rows[e.Item.ItemIndex].Delete();
Bind();
}
protected void btnAdd_Click(object sender, EventArgs e)
{
PopulateDataTable();
myTable.Rows.Add(myTable.NewRow());
ViewState["myTablestate"] = myTable;
Bind();
DataTable ImgTable1 = (DataTable)ViewState["ImgTablestate"];
GridImag.DataSource = ImgTable1;
GridImag.DataBind();
GridImag.SelectedIndex = -1;
}
protected void Repeater1_ItemDataBound(object sender, RepeaterItemEventArgs e)
{
if (e.Item.ItemType == ListItemType.Item ||
e.Item.ItemType == ListItemType.AlternatingItem)
{
var txtDescription = e.Item.FindControl("txtDescription") as DropDownList;
string degreeCode = Convert.ToString(((DataRowView)e.Item.DataItem)["degreeCode"]);
if (txtDescription != null)
{
txtDescription.DataSource = GH.GetCountries();
txtDescription.DataTextField = "EnglishName";
txtDescription.DataValueField = "id";
txtDescription.Items.Insert(0, new ListItem("---Select---", "0"));
txtDescription.DataBind();
if (txtDescription.Items.FindByValue(degreeCode) != null)
txtDescription.SelectedValue = degreeCode;
}
else
{
}
}
DataTable ImgTable1 = (DataTable)ViewState["ImgTablestate"];
GridImag.DataSource = ImgTable1;
GridImag.DataBind();
GridImag.SelectedIndex = -1;
}
protected void BindRepetDate()
{
RepeaterDate.DataSource = DateTable;
RepeaterDate.DataBind();
}
protected void PopulateDataTableDateRepet()
{
foreach (RepeaterItem item in RepeaterDate.Items)
{
TextBox txtDateFromPriceRepet = (TextBox)item.FindControl("txtDateFromPriceRepet");
TextBox txtDateToPriceRepet = (TextBox)item.FindControl("txtDateToPriceRepet");
TextBox txtPriceSpicific = (TextBox)item.FindControl("txtPriceSpicific");
DataRow row = DateTable.NewRow();
row["DateFrom"] = txtDateFromPriceRepet.Text;
row["DateTo"] = txtDateToPriceRepet.Text;
row["DatePrice"] = txtPriceSpicific.Text;
DateTable.Rows.Add(row);
}
}
protected void RepeaterDate_ItemCommand(object source, RepeaterCommandEventArgs e)
{
PopulateDataTableDateRepet();
DateTable.Rows[e.Item.ItemIndex].Delete();
BindRepetDate();
DataTable ImgTable1 = (DataTable)ViewState["ImgTablestate"];
GridImag.DataSource = ImgTable1;
GridImag.DataBind();
GridImag.SelectedIndex = -1;
}
protected void btnAddDateRepet_Click(object sender, EventArgs e)
{
PopulateDataTableDateRepet();
DateTable.Rows.Add(DateTable.NewRow());
BindRepetDate();
DataTable ImgTable1 = (DataTable)ViewState["ImgTablestate"];
GridImag.DataSource = ImgTable1;
GridImag.DataBind();
GridImag.SelectedIndex = -1;
}