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:
- <div>
- <fieldset>
- <legend>GridView selection using jquery</legend>
- <asp:GridView ID="GridView1" runat="server" AllowPaging="True" AllowSorting="True"
- AutoGenerateColumns="False" BackColor="LightGoldenrodYellow" BorderColor="Tan"
- BorderWidth="1px" CellPadding="2" DataKeyNames="SkuId" DataSourceID="sdsGridView"
- ForeColor="Black" GridLines="None"OnRowDataBound="GridView1_RowDataBound">
- <AlternatingRowStyle BackColor="PaleGoldenrod" />
- <Columns>
- <asp:TemplateField>
- <ItemTemplate>
- <input id="chkClick" name="chkClick" type="checkbox" />
- </ItemTemplate>
- </asp:TemplateField>
- <asp:BoundField DataField="SkuId" HeaderText="Id" ReadOnly="True"
- SortExpression="SkuId" />
- <asp:BoundField DataField="SkuName" HeaderText="Name" SortExpression="SkuName" />
- <asp:TemplateField>
- <ItemTemplate>
- <input id="txtQuantity" name="txtQuantity" type="text" />
- </ItemTemplate>
- </asp:TemplateField>
- <asp:TemplateField>
- <ItemTemplate>
- <asp:LinkButton ID="lnkEdit" runat="server" CausesValidation="false" CommandName="GridEdit"
- ClientIDMode="Static">Edit</asp:LinkButton>
- </ItemTemplate>
- </asp:TemplateField>
- <asp:TemplateField>
- <ItemTemplate>
- <asp:LinkButton ID="lnkSave" runat="server" CausesValidation="false" CommandName="GridSave"
- ClientIDMode="Static">Save</asp:LinkButton>
- </ItemTemplate>
- </asp:TemplateField>
- </Columns>
- <FooterStyle BackColor="Tan" />
- <HeaderStyle BackColor="Tan" Font-Bold="True" />
- <PagerStyle BackColor="PaleGoldenrod" ForeColor="DarkSlateBlue" HorizontalAlign="Center" />
- <SelectedRowStyle BackColor="DarkSlateBlue" ForeColor="GhostWhite" />
- <SortedAscendingCellStyle BackColor="#FAFAE7" />
- <SortedAscendingHeaderStyle BackColor="#DAC09E" />
- <SortedDescendingCellStyle BackColor="#E1DB9C" />
- <SortedDescendingHeaderStyle BackColor="#C2A47B" />
- </asp:GridView>
- <asp:SqlDataSource ID="sdsGridView" runat="server" ConnectionString="<%$ ConnectionStrings:DataConnectionString %>"
- SelectCommand="SELECT [SkuId], [SkuName] FROM [ProductSku] ORDER BY [SkuId]">
- </asp:SqlDataSource>
- </fieldset>
- </div>
Here's my page.aspx.cs Code:
- protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
- {
- if (e.Row.RowType == DataControlRowType.DataRow)
- {
- LinkButton lnkedit = e.Row.FindControl("lnkEdit") as LinkButton;
- lnkedit.CommandArgument = e.Row.RowIndex.ToString();
- LinkButton lnksave = e.Row.FindControl("lnkSave") as LinkButton;
- lnksave.CommandArgument = e.Row.RowIndex.ToString();
- int editId = int.Parse(e.Row.Cells[1].Text);
- int saveId = int.Parse(e.Row.Cells[1].Text);
- lnkedit.Attributes.Add("onClick", "LoadForEdit('" + editId + "');return false;");
- lnksave.Attributes.Add("onClick", "LoadForSave('" + saveId + "');return false;");
- }
Here's my Jquery Code:
- function LoadForEdit(gridViewId) {
- glbGridViewId = gridViewId;
- $('#txtQuantity').show('slow');
- return false;
- }
- function LoadForSave(GridViewId) {
- glbGridViewId = GridViewId;
- $('#txtQuantity').Hide('slow');
- return false;
- }
Any idea ?
Regards
Muhammad Atif Nadeem
Software Engineer
University of Karachi