Asp.Net Grid View Control column's cell show/hide using jquery

Asp.Net Grid View Control column's cell show/hide using jquery

Hi,

I am using .Net Framework 4.0 with Asp.Net C# along with Jquery v1.4.4 My problem is that how can i show textbox when i click on edit button and hide when i click on save button.


Here's my Asp.Net Code:

  1. <div>
  2.         <fieldset>
  3.             <legend>GridView selection using jquery</legend>
  4.             <asp:GridView ID="GridView1" runat="server" AllowPaging="True" AllowSorting="True"
  5.                 AutoGenerateColumns="False" BackColor="LightGoldenrodYellow" BorderColor="Tan"
  6.                 BorderWidth="1px" CellPadding="2" DataKeyNames="SkuId" DataSourceID="sdsGridView"
  7.                 ForeColor="Black" GridLines="None"OnRowDataBound="GridView1_RowDataBound">
  8.                 <AlternatingRowStyle BackColor="PaleGoldenrod" />
  9.                 <Columns>
  10.                  <asp:TemplateField>
  11.                         <ItemTemplate>
  12.                             <input id="chkClick" name="chkClick" type="checkbox" />      
  13.                         </ItemTemplate>
  14.                     </asp:TemplateField>
  15.                     <asp:BoundField DataField="SkuId" HeaderText="Id" ReadOnly="True"
  16.                         SortExpression="SkuId" />
  17.                     <asp:BoundField DataField="SkuName" HeaderText="Name" SortExpression="SkuName" />
  18.                     <asp:TemplateField>
  19.                         <ItemTemplate>
  20.                             <input id="txtQuantity" name="txtQuantity" type="text" />
  21.                         </ItemTemplate>
  22.                     </asp:TemplateField>
  23.                     <asp:TemplateField>
  24.                         <ItemTemplate>
  25.                             <asp:LinkButton ID="lnkEdit" runat="server" CausesValidation="false" CommandName="GridEdit"
  26.                                 ClientIDMode="Static">Edit</asp:LinkButton>
  27.                         </ItemTemplate>
  28.                     </asp:TemplateField>
  29.                     <asp:TemplateField>
  30.                         <ItemTemplate>
  31.                             <asp:LinkButton ID="lnkSave" runat="server" CausesValidation="false" CommandName="GridSave"
  32.                                 ClientIDMode="Static">Save</asp:LinkButton>
  33.                         </ItemTemplate>
  34.                     </asp:TemplateField>
  35.                 </Columns>
  36.                 <FooterStyle BackColor="Tan" />
  37.                 <HeaderStyle BackColor="Tan" Font-Bold="True" />
  38.                 <PagerStyle BackColor="PaleGoldenrod" ForeColor="DarkSlateBlue" HorizontalAlign="Center" />
  39.                 <SelectedRowStyle BackColor="DarkSlateBlue" ForeColor="GhostWhite" />
  40.                 <SortedAscendingCellStyle BackColor="#FAFAE7" />
  41.                 <SortedAscendingHeaderStyle BackColor="#DAC09E" />
  42.                 <SortedDescendingCellStyle BackColor="#E1DB9C" />
  43.                 <SortedDescendingHeaderStyle BackColor="#C2A47B" />
  44.             </asp:GridView>
  45.             <asp:SqlDataSource ID="sdsGridView" runat="server" ConnectionString="<%$ ConnectionStrings:DataConnectionString %>"
  46.                 SelectCommand="SELECT [SkuId], [SkuName] FROM [ProductSku] ORDER BY [SkuId]">
  47.             </asp:SqlDataSource>
  48.         </fieldset>
  49.     </div>

Here's my page.aspx.cs Code:

  1. protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
  2.         {
  3.             if (e.Row.RowType == DataControlRowType.DataRow)
  4.             {
  5.                 LinkButton lnkedit = e.Row.FindControl("lnkEdit") as LinkButton;
  6.                 lnkedit.CommandArgument = e.Row.RowIndex.ToString();

  7.                 LinkButton lnksave = e.Row.FindControl("lnkSave") as LinkButton;
  8.                 lnksave.CommandArgument = e.Row.RowIndex.ToString();

  9.                 int editId = int.Parse(e.Row.Cells[1].Text);
  10.                 int saveId = int.Parse(e.Row.Cells[1].Text);

  11.                 lnkedit.Attributes.Add("onClick", "LoadForEdit('" + editId + "');return false;");       
  12.                 lnksave.Attributes.Add("onClick", "LoadForSave('" + saveId + "');return false;"); 
  13.             }

Here's my Jquery Code:

  1. function LoadForEdit(gridViewId) {

  2.     glbGridViewId = gridViewId;
  3.     $('#txtQuantity').show('slow');
  4.     return false;
  5. }

  6. function LoadForSave(GridViewId) {

  7.     glbGridViewId = GridViewId;
  8.     $('#txtQuantity').Hide('slow');
  9.     return false;
  10. }  
Any idea ? 

Regards

Muhammad Atif Nadeem
Software Engineer
University of Karachi