Click here to Skip to main content
16,018,949 members
Please Sign up or sign in to vote.
2.00/5 (1 vote)
See more:
Hi,

I have a usercontrol and Gridview inside it. Gridview has two columns one has file uploader and second has textbox.

Using javascript I am adding new row to gridview, so that my uploader and textbox get repeated on every row.

I put this user control in other aspx page.

From the code behind i want to access all file uploaders and textboxes, but not able to find them.

I am giving you my Usercontrol markup.
Pls get me some logic to crack this.
---------- markup -----------
XML
<%@ 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>



-----------------------------
Thanks,
Hemant
Posted

1 solution

Read this simple and small QA page

http://forums.asp.net/p/1174306/1974016.aspx[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900