GridView中页脚的问题. [英] Problem with footer in gridview..

查看:63
本文介绍了GridView中页脚的问题.的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨..
我有一个包含三列的gridview,每列都有一个文本框,并且我有一个带有三个文本框的页脚,
我的要求是,当我填充gridview页脚中的三个文本框并按添加按钮时,值应显示在grid视图的3列中..
在页面加载时,我正在提供一个表格作为gridview的源.


任何人都可以帮我吗.

谢谢.....
这是我要求的设计代码.

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.

<br />
<pre lang="xml"><div><br />
 <asp:GridView ID="gvMultipleInsertion" runat="server" AutoGenerateColumns="false"<br />
          ShowFooter="true" ><br />
 <Columns><br />
 <asp:TemplateField HeaderText="Name"><br />
 <ItemTemplate><br />
 <asp:TextBox ID="txtName" runat="server" Width="200px"></asp:TextBox><br />
 </ItemTemplate><br />
 <FooterTemplate><br />
 <asp:TextBox ID="txtFName" runat="server" Width="200px"></asp:TextBox><br />
 </FooterTemplate><br />
 </asp:TemplateField><br />
 <asp:TemplateField HeaderText="Designation"><br />
 <ItemTemplate><br />
 <asp:TextBox ID="txtDesignation" runat="server" Width="200px"></asp:TextBox><br />
 </ItemTemplate><br />
 <FooterTemplate ><br />
 <asp:TextBox ID="txtFDesignation" runat="server" Width="200px"></asp:TextBox><br />
 </FooterTemplate><br />
 </asp:TemplateField><br />
 <asp:TemplateField HeaderText="Salary"><br />
 <ItemTemplate><br />
 <asp:TextBox ID="txtSalary" runat="server" Width="200px"></asp:TextBox><br />
 </ItemTemplate><br />
<FooterTemplate ><br />
<asp:TextBox ID="txtFSalary" runat="server" Width="200px"></asp:TextBox><br />
</FooterTemplate><br />
 </asp:TemplateField><br />
 </Columns><br />
<FooterStyle BackColor="BlueViolet" /><br />
 </asp:GridView><br />
 <asp:Button ID="btnAdd" runat="server" Text="ADD" Width="50px"<br />
          onclick="btnAdd_Click" /><br />
 &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;<br />
 <asp:Button ID="btnSave" Text="Save" runat="server" onclick="btnSave_Click" /><br />
  &nbsp;<br />
  </div></pre><br />
<br />

推荐答案

添加新的Template字段,然后在此按钮上添加Add按钮,以重新插入recore和Fillgrid.
add new Template field and Place Add button on this button insert recore and Fillgrid again so simple.


Student.aspx
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



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;
        }
    }

}


这篇关于GridView中页脚的问题.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆