<%@ Control Language="C#" AutoEventWireup="true" ClientIDMode="Static" Inherits="User_Controls_uclDynamicUploader" CodeBehind="uclDynamicUploader.ascx.cs" %> <script language="javascript" type="text/javascript"> // function will add new row to grid if user clicks "+" image. function AddRow() { var hdnMaxGrid = document.getElementById('hdn001UctlMaxGrid').value // gets hidden variable value. var grd = this.document.getElementById('grd'); if (grd.rows.length == Number(hdnMaxGrid) && Number(hdnMaxGrid) != 0) { alert("Can't add more"); return false; } var tbod = grd.rows[0].parentNode; var newRow = grd.rows[grd.rows.length - 1].cloneNode(true); tbod.appendChild(newRow); var rowIdx = 1; for (rowIdx; rowIdx < grd.rows.length; rowIdx++) { var txtbox = grd.rows[rowIdx].cells[2].firstChild; var pp = txtbox.value; document.getElementById('hdnpp').value = pp; } return false; } // function will delete row from grid if user clicks "-" image on that row. function RemoveRow(ctrl) { var grd = document.getElementById('grd'); var row = ctrl.parentNode.parentNode; //to get row containing image var rowIndex = row.rowIndex; //row index of that row. if (grd.rows.length < 2) { alert("Can not delete"); } else { grd.deleteRow(rowIndex); } return false; } </script> <div id="divTable" runat="server"> <asp:HiddenField ID="hdnpp" runat="server" /> <table> <tr> <td valign="top"> <asp:GridView ID="grd" runat="server" AutoGenerateColumns="False" PagerStyle-HorizontalAlign="Left" HeaderStyle-CssClass="tbhdr" CssClass="link"> <Columns> <asp:TemplateField HeaderText="Delete"> <ItemTemplate> <asp:ImageButton ID="imgbtnDelete" runat="server" OnClientClick="return RemoveRow(this)" ImageUrl="~/Images/Remove.png" ToolTip="Delete Row" /> </ItemTemplate> </asp:TemplateField> <asp:TemplateField HeaderText="Attachments"> <ItemTemplate> <asp:FileUpload ID="FUpd" runat="server" /> </ItemTemplate> </asp:TemplateField> <asp:TemplateField HeaderText="Title"> <ItemTemplate> <asp:TextBox ID="txt001UctlFileTitle" runat="server"></asp:TextBox> </ItemTemplate> </asp:TemplateField> </Columns> <HeaderStyle CssClass="tbhdr"></HeaderStyle> <PagerStyle HorizontalAlign="Left"></PagerStyle> </asp:GridView> <asp:HiddenField ID="hdn001UctlMaxGrid" runat="server" Value="0" /> </td> <td valign="top"> <asp:ImageButton ID="imgbtnAddNew" runat="server" ImageUrl="~/Images/Add.png" OnClientClick="return AddRow()" ToolTip="Add Row" /> </td> </tr> </table> </div>
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)