我正在使用一个类文件在gridview中绑定dropdownlist。我按图像按钮添加每一行,之后我选择dropdownlist图像按钮将不起作用,最终,我有了一个带有ajax ToolkitScriptManager的更新面板。使用EventValidation是false图像按钮可以正常工作,所选的下拉列表值将消失。
<ajax:ToolkitScriptManager ID="ToolkitScriptManager1" runat="server"/>
<asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode="Conditional">
<ContentTemplate>
<asp:GridView ID="travel_grid" runat="server" OnRowDataBound="travel_grid_RowDataBound" OnRowDeleting="travel_grid_RowDeleting" >
<Columns>
<asp:TemplateField>
<FooterTemplate>
<asp:Label ID="Label43" runat="server"></asp:Label>
<asp:ImageButton ID="ButtonAdd" runat="server" BorderStyle="None"ImageUrl="~/images/addbutton.png" OnClick="ButtonAdd_Click1" />
</FooterTemplate>
<ItemTemplate>
<asp:DropDownList ID="ddlContinent" runat="server" ></asp:DropDownList>
<ajax:CascadingDropDown ID="ContinentCascading" runat="server" Category="Continent" TargetControlID="ddlContinent" LoadingText="Loading Continent..." PromptText="Select Continent" ServiceMethod="BindContinentdropdown" ServicePath="DropdownWebService.asmx">
</ajax:CascadingDropDown>
</ItemTemplate>
</asp:TemplateField>
<asp:CommandField ButtonType="Image" DeleteImageUrl="~/images/delete.png" ItemStyle-CssClass="delete-btn" ShowDeleteButton="True">
</asp:CommandField>
</Columns>
<EmptyDataRowStyle />
</asp:GridView>
Dropdownwebservice.cs
public CascadingDropDownNameValue[] BindContinentdropdown(string knownCategoryValues, string category)
{
List<CascadingDropDownNameValue> continentdetails = new List<CascadingDropDownNameValue>();
try
{
MySqlConnection concontinent = new MySqlConnection(connection);
concontinent.Open();
string cmdcountry = "select * from continent";
MySqlDataAdapter dacontinent = new MySqlDataAdapter(cmdcountry, connection);
MySqlCommand MyCommand = new MySqlCommand(cmdcountry, concontinent);
MyCommand.ExecuteNonQuery();
DataSet dscontinent = new DataSet();
dacontinent.Fill(dscontinent);
concontinent.Close();
foreach (DataRow dtrow in dscontinent.Tables[0].Rows)
{
string ContinentCode = dtrow["continent_code"].ToString();
string ContinentName = dtrow["continent_name"].ToString();
continentdetails.Add(new CascadingDropDownNameValue(ContinentName, ContinentCode));
}
}
catch (Exception ex)
{
}
return continentdetails.ToArray();
}