Я хочу, чтобы мой gridview расширялся и сворачивался при нажатии кнопки asp. Но я не могу вызвать JavaScript в моей кнопке.
Вот javascript, который обрабатывает развертывание и свертывание.
function divexpandcollapse(divname) {
var div = document.getElementById(divname);
var img = document.getElementById('img' + divname);
if (div.style.display == "none") {
div.style.display = "inline";
img.src = "../images/minus.gif";
return false;
} else {
div.style.display = "none";
img.src = "../images/plus.gif";
return false;
}
}
Вот конец ветки:
<asp:TemplateField ItemStyle-Width="20px" >
<ItemTemplate>
<a href="JavaScript:divexpandcollapse('div<%# Eval("componente_id") %>');" onclick="" >
<img id="imgdiv<%# Eval("componente_id") %>" width="9px" border="0" src="../images/plus.gif"
alt="" /> </a>
<asp:ImageButton ImageUrl="~/images/select.png" runat="server" CommandName="Select" OnRowDataBound = "OnRowDataBound" Width="10px" Height="10px"/>
</ItemTemplate>
<ItemStyle Width="20px" VerticalAlign="Middle"></ItemStyle>
</asp:TemplateField>
<asp:TemplateField HeaderText="Purchase Order ID">
<ItemTemplate>
<asp:Label ID="lblPurchaseOrderID" runat="server" Text='<%#DataBinder.Eval(Container.DataItem, "componente_id") %>' ></asp:Label>
</ItemTemplate>
Я попытался добавить кнопку с изображением вот так
<asp:ImageButton ImageUrl="~/Images/plus.gif" runat="server" CommandName="Update" ToolTip="Update" Width="10px" Height="10px" OnClientClick="JavaScript:divexpandcollapse('div<%# Eval("componente_id") %>');" />
в ItemTemplate, однако, это не работает. Как я могу изменить код, чтобы расширение происходило по нажатию кнопки aspButton? Спасибо.