Image disappears after click event
Hi,
I am working on nested gridview concept...
Here is the html source and the javascript function ... The image in the gridview disappears after a user clicks on it.. Why is it happening so? Please correct me.
<script type="text/javascript">
function expandcollapse(obj,row)
{
var div = document.getElementById(obj);
var img = document.getElementById('img' + obj);
if (div.style.display == "none")
{
div.style.display = "block";
if (row == 'alt')
{
img.src = "minus.gif";
}
else
{
img.src = "minus.gif";
}
img.alt = "Close to view other item location";
}
else
{
div.style.display = "none";
if (row == 'alt')
{
img.src = "plus.gif";
}
else
{
img.src = "plus.gif";
}
img.alt = "Expand to show item location";
}
}
</script>
===========================================
<asp:GridView ID="GridView1" AllowPaging="True"
AutoGenerateColumns="false" DataSourceID="SqlDataSource1" DataKeyNames="ItemID"
ShowFooter="true" Font-Size="8.25pt"
Font-Names="Tahoma" runat="server"
Width="800px" onrowdatabound="GridView1_RowDataBound"
BorderColor="#666699" BorderStyle="Solid">
<HeaderStyle BackColor="AliceBlue" ForeColor="#666699"/>
<FooterStyle BackColor="White" />
<Columns>
<asp:TemplateField>
<ItemTemplate>
<a href="javascript:expandcollapse('div<%# Eval("ItemID") %>', 'one');">
<img id="imgdiv<%# Eval("ItemID") %>" alt="Click to show/hide item location <%# Eval("ItemID") %>" width="9px" style="border:0" src="images/plus.gif"/>
</a>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Item ID">
<ItemTemplate>
<asp:Label ID="lblItemID" runat="server" Text='<%#Eval("ItemID") %>'></asp:Label>
</ItemTemplate>
<EditItemTemplate>
<asp:Label ID="lblItemID" runat="server" Text=""></asp:Label> </EditItemTemplate>
<FooterTemplate>
<asp:Label ID="lblItemID" runat="server" Text=""></asp:Label>
</FooterTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Item Name">
<ItemTemplate>
<asp:Label ID="lblitemname" runat="server" Text='<%#Eval("ItemName") %>'></asp:Label>
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox ID="txtitemname" runat="server" Text='<%#Eval("ItemName") %>' Font-Names="Tahoma" Font-Size="8.25pt"></asp:TextBox>
</EditItemTemplate>
<FooterTemplate>
<asp:TextBox ID="txtitemname" runat="server" Text="" Font-Names="Tahoma" Font-Size="8.25pt"></asp:TextBox>
</FooterTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Item Code">
<ItemTemplate>
<asp:Label ID="lblitemcode" runat="server" Text='<%#Eval("ItemCode") %>'></asp:Label>
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox ID="txtitemcode" runat="server" Text='<%#Eval("ItemCode") %>' Font-Names="Tahoma" Font-Size="8.25pt"></asp:TextBox>
</EditItemTemplate>
<FooterTemplate>
<asp:TextBox ID="txtitemcode" runat="server" Text="" Font-Names="Tahoma" Font-Size="8.25pt"></asp:TextBox>
</FooterTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Group Name">
<ItemTemplate>
<asp:Label ID="lblGroupName" runat="server" Text='<%#Eval("GroupName") %>'></asp:Label>
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox ID="txtgroupname" runat="server" Text='<%#Eval("GroupName") %>' Font-Names="Tahoma" Font-Size="8.25pt"></asp:TextBox>
</EditItemTemplate>
<FooterTemplate>
<asp:TextBox ID="txtgroupname" runat="server" Text="" Font-Names="Tahoma" Font-Size="8.25pt"></asp:TextBox>
</FooterTemplate>
</asp:TemplateField>
<%-- <asp:BoundField DataField="ItemID" HeaderText="Item ID" />
<asp:BoundField DataField="ItemName" HeaderText="Item Name" />
<asp:BoundField DataField="ItemCode" HeaderText="Item Code" />
<asp:BoundField DataField="GroupName" HeaderText="Group Name" />--%>
<asp:CommandField HeaderText="Edit" ShowEditButton="True" />
<asp:TemplateField HeaderText="Delete">
<ItemTemplate>
<asp:LinkButton ID="linkDeleteItem" CommandName="Delete" runat="server">Delete</asp:LinkButton>
</ItemTemplate>
<FooterTemplate>
<asp:LinkButton ID="linkAddItem" CommandName="AddCustomer" runat="server">Add</asp:LinkButton>
</FooterTemplate>
</asp:TemplateField>
<asp:TemplateField>
<ItemTemplate>
<tr>
<td colspan="100%">
<div id="div<%# Eval("ItemID") %>" style="display:none;position:relative;left:15px;OVERFLOW: auto;WIDTH:97%" >
<asp:GridView ID="GridView2" AllowPaging="True" AllowSorting="true" BackColor="White" Width="100%" Font-Size="X-Small"
AutoGenerateColumns="false" Font-Names="Verdana" runat="server" DataKeyNames="ItemID" ShowFooter="true"
BorderStyle="Double" BorderColor="#0083C1">
<RowStyle BackColor="Gainsboro" />
<AlternatingRowStyle BackColor="White" />
<HeaderStyle BackColor="AliceBlue" ForeColor="#666699"/>
<FooterStyle BackColor="White" />
<Columns>
<asp:TemplateField>
<ItemTemplate>
<asp:Label ID="lblocid" Text='<%#Eval("Item_LocationID") %>' runat="server"></asp:Label>
</ItemTemplate>
<EditItemTemplate>
<asp:Label ID="lblocid" Text='<%#Eval("Item_LocationID") %>' runat="server"></asp:Label>
</EditItemTemplate>
<FooterTemplate>
<asp:Label ID="lblocid" Text="" runat="server"></asp:Label>
</FooterTemplate>
</asp:TemplateField>
<asp:TemplateField>
<ItemTemplate>
<asp:Label ID="lblitemid" runat="server" Text='<%#Eval("ItemID") %>'></asp:Label>
</ItemTemplate>
<EditItemTemplate>
<asp:Label ID="lblitemid" runat="server" Text='<%#Eval("ItemID") %>'></asp:Label>
</EditItemTemplate>
<FooterTemplate>
<asp:Label ID="lblitemid" runat="server" Text=""></asp:Label>
</FooterTemplate>
</asp:TemplateField>
<asp:TemplateField>
<ItemTemplate>
<asp:Label ID="lbllocname" runat="server" Text='<%#Eval("LocationName") %>'></asp:Label>
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox ID="txtlocname" Text='<%#Eval("LocationName") %>' runat="server" Font-Names="Tahoma" Font-Size="8.25pt"></asp:TextBox>
</EditItemTemplate>
<FooterTemplate>
<asp:TextBox ID="txtlocname" Text="" runat="server" Font-Names="Tahoma" Font-Size="8.25pt"></asp:TextBox>
</FooterTemplate>
</asp:TemplateField>
<asp:TemplateField>
<ItemTemplate>
<asp:Label ID="lblstore" Text='<%#Eval("StoreName") %>' runat="server"></asp:Label>
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox ID="txtstore" Text='<%#Eval("StoreName") %>' runat="server" Font-Names="Tahoma" Font-Size="8.25pt"></asp:TextBox>
</EditItemTemplate>
<FooterTemplate>
<asp:TextBox ID="txtstore" Text="" runat="server" Font-Names="Tahoma" Font-Size="8.25pt"></asp:TextBox>
</FooterTemplate>
</asp:TemplateField>
<%--<asp:BoundField DataField="Item_LocationID" HeaderText="Item Location ID" />
<asp:BoundField DataField="ItemID" HeaderText="Item ID" />
<asp:BoundField DataField="LocationName" HeaderText="Location" />
<asp:BoundField DataField="StoreName" HeaderText="Store" />--%>
<asp:CommandField HeaderText="Edit" ShowEditButton="True" />
<asp:TemplateField HeaderText="Delete">
<ItemTemplate>
<asp:LinkButton ID="linkDeleteItemL" CommandName="Delete" runat="server">Delete</asp:LinkButton>
</ItemTemplate>
<FooterTemplate>
<asp:LinkButton ID="linkAddItemL" CommandName="AddOrder" runat="server">Add</asp:LinkButton>
</FooterTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
</div>
</td>
</tr>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>