Click here to Skip to main content
15,911,891 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi..
i have a gridview with three columns and each column is having a textbox, and i have a footer having three textbox's ,
My requirement is when i fill the three textboxes in the footer of the gridview and press add button then the values should be displayed in the 3 columns of the grid view.....
at the time of page load i am giving a table as source to the gridview .


Can any one Please help Me..

thanks.....
this is the my design code of my requirement.
XML
<div>
 <asp:GridView ID="gvMultipleInsertion" runat="server" AutoGenerateColumns="false"
          ShowFooter="true" >
 <Columns>
 <asp:TemplateField HeaderText="Name">
 <ItemTemplate>
 <asp:TextBox ID="txtName" runat="server" Width="200px"></asp:TextBox>
 </ItemTemplate>
 <FooterTemplate>
 <asp:TextBox ID="txtFName" runat="server" Width="200px"></asp:TextBox>
 </FooterTemplate>
 </asp:TemplateField>
 <asp:TemplateField HeaderText="Designation">
 <ItemTemplate>
 <asp:TextBox ID="txtDesignation" runat="server" Width="200px"></asp:TextBox>
 </ItemTemplate>
 <FooterTemplate >
 <asp:TextBox ID="txtFDesignation" runat="server" Width="200px"></asp:TextBox>
 </FooterTemplate>
 </asp:TemplateField>
 <asp:TemplateField HeaderText="Salary">
 <ItemTemplate>
 <asp:TextBox ID="txtSalary" runat="server" Width="200px"></asp:TextBox>
 </ItemTemplate>
<FooterTemplate >
<asp:TextBox ID="txtFSalary" runat="server" Width="200px"></asp:TextBox>
</FooterTemplate>
 </asp:TemplateField>
 </Columns>
<FooterStyle BackColor="BlueViolet" />
 </asp:GridView>
 <asp:Button ID="btnAdd" runat="server" Text="ADD" Width="50px"
          onclick="btnAdd_Click" />
 &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
 <asp:Button ID="btnSave" Text="Save" runat="server" onclick="btnSave_Click" />
  &nbsp;
  </div>
Posted
Updated 14-Jun-11 21:33pm
v4
Comments
[no name] 15-Jun-11 2:14am    
post what you have done so far, let us take a look and correct the mistake

add new Template field and Place Add button on this button insert recore and Fillgrid again so simple.
 
Share this answer
 
Comments
prabhu460 15-Jun-11 2:18am    
thank's for u r replay ,
can u send me any related example code or link....
Student.aspx
<div id="dvStudentVarification" runat="server" style="width: 900px">
    <asp:UpdatePanel ID="upStudentVarification1" runat="server">
        <contenttemplate>
    <asp:HiddenField ID="hfSVEditCtl" runat="server" />
    <asp:GridView runat="server" AutoGenerateColumns="False" CellPadding="4" DataKeyNames="StudentVarificationId"
        SkinID="gvGrey" ID="dgvStudentVarification" meta:resourceKey="dgvStudentVarificationResource1"
        OnRowDeleting="dgvStudentVarification_RowDeleting" OnRowDataBound="dgvStudentVarification_RowDataBound"
        OnRowCommand="dgvStudentVarification_RowCommand">
        <Columns>
            <asp:TemplateField HeaderText="Student Name" meta:resourceKey="TemplateFieldResource1">
                <EditItemTemplate>
                    <asp:TextBox runat="server" CssClass="grid-txt-fid" Width="150px" ID="txtStudentName"
                        meta:resourceKey="txtStudentNameResource1"></asp:TextBox>
                    <asp:Label runat="server" Text="This field cannot be blank" CssClass="feedtab_cont_span"
                        ID="lblrfvSVStudentName" Visible="False" meta:resourceKey="lblrfvSVStudentNameResource1"></asp:Label>
                </EditItemTemplate>
                <ItemTemplate>
                    <asp:Label runat="server" Text='<%# Bind("StudentName") %>' ID="lblStudentName" meta:resourceKey="lblStudentNameResource1"></asp:Label>
                    &nbsp;
                </ItemTemplate>
                <HeaderStyle CssClass="title-grid" Width="150px"></HeaderStyle>
            </asp:TemplateField>
            <asp:TemplateField HeaderText="Other Information to Student" meta:resourceKey="TemplateFieldResource2">
                <EditItemTemplate>
                    <asp:DropDownList runat="server" DataTextField="MiscDescription" DataValueField="MiscId"
                        DataSource="<%# OtherInfo() %>" CssClass="grid-list" Width="110px" ID="cmbRelationShip"
                        meta:resourceKey="cmbRelationShipResource1">
                    </asp:DropDownList>
                </EditItemTemplate>
                <ItemTemplate>
                    <asp:Label runat="server" Text='<%# Bind("OtherInfo") %>' ID="lblRelationShip"
                        meta:resourceKey="lblRelationShipResource1"></asp:Label>
                    &nbsp;
                </ItemTemplate>
                <HeaderStyle CssClass="title-grid" width="110px"></HeaderStyle>
            </asp:TemplateField>
            <asp:TemplateField HeaderText="Student Grade" meta:resourceKey="TemplateFieldResource3">
                <EditItemTemplate>
                    <asp:DropDownList runat="server" DataTextField="MiscDescription" DataValueField="MiscId"
                        DataSource="<%# BindStudentGrade() %>" CssClass="grid-list" Width="70px" ID="cmbStudentGrade"
                        meta:resourceKey="cmbStudentGradeResource1">
                    </asp:DropDownList>
                </EditItemTemplate>
                <ItemTemplate>
                    <asp:Label runat="server" Text='<%# Bind("StudentGrade") %>' ID="lblStudentGrade"
                        meta:resourceKey="lblStudentGradeResource1"></asp:Label>
                    &nbsp;
                </ItemTemplate>
                <HeaderStyle CssClass="title-grid" width="75px"></HeaderStyle>
            </asp:TemplateField>
            <asp:TemplateField HeaderText="School Name" meta:resourceKey="TemplateFieldResource4">
                <EditItemTemplate>
                    <asp:TextBox runat="server" CssClass="grid-txt-fid" ID="txtSchoolName" meta:resourceKey="txtSchoolNameResource1"></asp:TextBox>
                </EditItemTemplate>
                <ItemTemplate>
                    <asp:Label runat="server" Text='<%# Bind("SchoolName") %>' ID="lblSchoolName" meta:resourceKey="lblSchoolNameResource1"></asp:Label>
                    &nbsp;
                </ItemTemplate>
                <HeaderStyle CssClass="title-grid"></HeaderStyle>
            </asp:TemplateField>
            <asp:TemplateField HeaderText="School Number" meta:resourceKey="TemplateFieldResource5">
                <EditItemTemplate>
                    <asp:TextBox runat="server" CssClass="grid-txt-fid" ID="txtSchoolNumber" meta:resourceKey="txtSchoolNumberResource1"></asp:TextBox>
                </EditItemTemplate>
                <ItemTemplate>
                    <asp:Label runat="server" Text='<%# Bind("SchoolNumber") %>' ID="lblSchoolNumber"
                        meta:resourceKey="lblSchoolNumberResource1"></asp:Label>
                    &nbsp;
                </ItemTemplate>
                <HeaderStyle CssClass="title-grid"></HeaderStyle>
            </asp:TemplateField>
            <asp:TemplateField HeaderText="Student Program" meta:resourceKey="TemplateFieldResource6">
                <EditItemTemplate>
                    <asp:CheckBoxList runat="server" DataTextField="MiscDescription" DataValueField="MiscId"
                        DataSource="<%# BindStudentProgram() %>" CssClass="grid-list" Width="150px" ID="cblStudentProgram"
                        Style="width: 180px" meta:resourceKey="cblStudentProgramResource1">
                    </asp:CheckBoxList>
                    <%--<asp:Label runat="server" Text="other(Please specify)" ID="lblOtherCaption" meta:resourceKey="lblOtherCaptionResource1"></asp:Label>--%>
                    <asp:TextBox runat="server" CssClass="grid-txt-fid" Width="180px" ID="txtOtherProgram"
                        meta:resourceKey="txtOtherProgramResource1"></asp:TextBox>
                </EditItemTemplate>
                <ItemTemplate>
                    <asp:Label runat="server" Text='<%# Bind("StudentProgram") %>' ID="lblStudentProgram"
                        meta:resourceKey="lblStudentProgramResource1"></asp:Label>
                </ItemTemplate>
                <HeaderStyle CssClass="title-grid" Width="155px"></HeaderStyle>
            </asp:TemplateField>
            <asp:TemplateField HeaderText="Action" ShowHeader="False" meta:resourceKey="TemplateFieldResource7">
                <EditItemTemplate>
                    <asp:ImageButton runat="server" CommandName="Insert" CausesValidation="False" ValidationGroup="vsSV"
                        AlternateText="Click here to add new record." ImageUrl="~/votnetimg/add.png" ToolTip="Click here to add new record."
                        ID="lnkAdd" meta:resourceKey="lnkAddResource1"></asp:ImageButton>
                </EditItemTemplate>
                <ItemTemplate>
                    <asp:ImageButton runat="server" CommandName="delete" CausesValidation="False" AlternateText="Click here to remove record."
                        ImageUrl="votnetimg/delete.png" ToolTip="Click here to remove record." ID="lnkDelete"
                        meta:resourceKey="lnkDeleteResource1"></asp:ImageButton>
                </ItemTemplate>
                <HeaderStyle CssClass="title-grid" Width="20px"></HeaderStyle>
            </asp:TemplateField>
        </Columns>
    </asp:GridView>
    </contenttemplate>
    </asp:UpdatePanel>
</div>


Student.aspx.cs
protected void dgvStudentVarification_RowCommand(object sender, GridViewCommandEventArgs e)
{

    if (e.CommandName.Equals("Insert"))
    {
        #region Working Code Footer Style

        DataTable dt = (DataTable)_SessionStudentVarificationData;

        GridViewRow gRow = dgvStudentVarification.Rows[dgvStudentVarification.Rows.Count - 1];

        Label lblrfvSVStudentName = (Label)gRow.FindControl("lblrfvSVStudentName");
        TextBox txtStudentName = (TextBox)gRow.FindControl("txtStudentName");

        TextBox txtSchoolName = (TextBox)gRow.FindControl("txtSchoolName");
        TextBox txtSchoolNumber = (TextBox)gRow.FindControl("txtSchoolNumber");
        TextBox txtOtherProgram = (TextBox)gRow.FindControl("txtOtherProgram");

        DropDownList cmbRelationShip = (DropDownList)gRow.FindControl("cmbRelationShip");
        DropDownList cmbStudentGrade = (DropDownList)gRow.FindControl("cmbStudentGrade");
        CheckBoxList cblStudentProgram = (CheckBoxList)gRow.FindControl("cblStudentProgram");


        if (txtStudentName.Text == "")
        {
            lblrfvSVStudentName.Visible = true;
            return;
        }
        lblrfvSVStudentName.Visible = false;

        dt.Rows.RemoveAt(dt.Rows.Count - 1);

        string lstrProgram = string.Empty;
        string lstrProgramID = string.Empty;

        for (int lintLoop = 0; lintLoop < cblStudentProgram.Items.Count; lintLoop++)
        {
            if (cblStudentProgram.Items[lintLoop].Selected && cblStudentProgram.Items[lintLoop].Text != "Other (Please specify)")
            {
                lstrProgram += cblStudentProgram.Items[lintLoop].Text + "<br/>";
                lstrProgramID += cblStudentProgram.Items[lintLoop].Value + ",";
            }
        }

        lstrProgram = txtOtherProgram.Text == "" ? lstrProgram : lstrProgram + txtOtherProgram.Text;

        dt.Rows.Add(new object[] { dt.Rows.Count + 1, txtStudentName.Text, cmbRelationShip.Items[cmbRelationShip.SelectedIndex].Text, cmbStudentGrade.Items[cmbStudentGrade.SelectedIndex].Text, txtSchoolName.Text, txtSchoolNumber.Text, lstrProgram, cmbRelationShip.SelectedValue, cmbStudentGrade.SelectedValue, lstrProgramID, txtOtherProgram.Text });
        dt.Rows.Add(new object[] { dt.Rows.Count + 1, "", "", "", "", "", "", -1, -1, "", "" });

        _SessionStudentVarificationData = dt;

        BindStudentVarificationGrid();

        dvStudentVarification.Style["hieght"] = dgvStudentVarification.Height.ToString();

        #endregion
    }
}

protected void dgvStudentVarification_RowDataBound(object sender, GridViewRowEventArgs e)
{
    if (e.Row.RowType == DataControlRowType.DataRow)
    {
        common.MouseoverGrid(sender, e);
    }
}

protected void dgvStudentVarification_RowDeleting(object sender, GridViewDeleteEventArgs e)
{
    DataTable dt = (DataTable)_SessionStudentVarificationData;
    dt.Rows.RemoveAt(e.RowIndex);
    _SessionStudentVarificationData = dt;
    BindStudentVarificationGrid();
}

protected void cblStudentProgram_SelectedIndexChanged(object sender, EventArgs e)
{
    TextBox txtOtherProgram = (TextBox)dgvStudentVarification.FooterRow.FindControl("txtOtherProgram");
    CheckBoxList cblStudentProgram = (CheckBoxList)dgvStudentVarification.FooterRow.FindControl("cblStudentProgram");

    for (int lintLoop = 0; lintLoop < cblStudentProgram.Items.Count; lintLoop++)
    {

        if (cblStudentProgram.Items[lintLoop].Text == "Other")
        {
            txtOtherProgram.Visible = cblStudentProgram.Items[lintLoop].Selected;
        }
    }

}
 
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