I have a gridview column that's gets a large amount of text from the server. So instead of showing all that text after the grid loads I want to show it only if a user clicks an Expand link then closes it with a collapse link. Here is what I have. Please note that I already know that I can put both javascript functions in one; I'm testing right now in two separate functions.
<script type="text/javascript" language="javascript" >
function hidelink() {
var col = $get('col');
var exp = $get('exp');
col.style.display = 'none';
exp.style.display = '';
}
function showlink(){
var col = $get('col');
var exp = $get('exp');
col.style.display = '';
exp.style.display = 'none';
}
<asp:GridView ID="GridView2" Width="400px" runat="server" AutoGenerateColumns="False"
AllowPaging ="True"
BackColor="White" BorderColor="#999999"
BorderStyle="None" BorderWidth="1px"
CellPadding="3" DataKeyNames="APPID"
DataSourceID="SqlDataSource3"
PagerSettings-Mode="NextPreviousFirstLast" EnableSortingAndPagingCallbacks="True">
<PagerSettings Mode="NextPreviousFirstLast" />
<RowStyle BackColor="#EEEEEE" ForeColor="Black" />
<Columns>
<asp:BoundField DataField="stuff" HeaderText="Name" ReadOnly="True"
SortExpression="app" />
<asp:BoundField DataField="Description" HeaderText="Short Descr"
ReadOnly="True" SortExpression="des" />
<asp:TemplateField HeaderText="Long Descr" SortExpression="data">
<EditItemTemplate>
<asp:TextBox ID="TextBox1" runat="server" Text='<%# Bind("data") %>'></asp:TextBox>
</EditItemTemplate>
<ItemTemplate>
<div id="col">
<asp:LinkButton ID="expand" runat="server" OnClientClick ="hidelink();return false;">Expand</asp:LinkButton>
</div>
<div id="exp" style="display:none">
<asp:LinkButton ID="collapse" runat="server" OnClientClick ="showlink();return false;">Collapse</asp:LinkButton>
</div>
<asp:Panel ID="Panel1" runat="server" >
<table>
<tr>
<td> <%#Eval("LongDescription")%>
</td>
</tr>
</table>
My issue is that only the first record does everything it should. (expand/collapse) but the other rows only expand and does not hide the expand link in the div tag. It is only finding the id of the first row because when the expand button is hit on any other row it changes the first row to show the collapse link. How can i fix this?