Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/36.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 合并Templatefield与Boundfield_C#_Asp.net_.net_Gridview_Merge - Fatal编程技术网

C# 合并Templatefield与Boundfield

C# 合并Templatefield与Boundfield,c#,asp.net,.net,gridview,merge,C#,Asp.net,.net,Gridview,Merge,我有一个行字段,其中包含与前一行相同的值。我可以使用boundField将其合并,但当我将其更改为templateField时,代码中的最后一行无法正常工作。因此,我使用boundfield(将最后一行更改为boundfield)对其进行了比较,结果成功了。我使用templatefield的原因是我想使用linkbutton命令参数,这样它就可以使用会话将所选数据传递到另一个页面。所以我的问题是,为什么合并不能很好地与模板字段一起工作?但它对束缚场的作用好吗?我仍然想使用模板字段,因为链接按钮。

我有一个行字段,其中包含与前一行相同的值。我可以使用boundField将其合并,但当我将其更改为templateField时,代码中的最后一行无法正常工作。因此,我使用boundfield(将最后一行更改为boundfield)对其进行了比较,结果成功了。我使用templatefield的原因是我想使用linkbutton命令参数,这样它就可以使用会话将所选数据传递到另一个页面。所以我的问题是,为什么合并不能很好地与模板字段一起工作?但它对束缚场的作用好吗?我仍然想使用模板字段,因为链接按钮。但是,如果有人能给我一个例子,使用绑定字段和链接,我愿意使用它

这是我的aspx代码

<asp:GridView ID="GridViewApproval" AutoGenerateColumns="false" runat="server" CssClass="Grid" AllowPaging="true"       
    Width="100%" OnDataBound="OnDataBound" ShowHeaderWhenEmpty="true" EmptyDataText="No Data Found">

     <Columns>

        <asp:TemplateField HeaderText="No.">
            <ItemTemplate>
                <asp:Label ID="lblNo" runat="server"
                    Text = '<%# Container.DataItemIndex + 1 %>'> </asp:Label>
            </ItemTemplate>
        </asp:TemplateField>

         <asp:BoundField DataField="EMPLOYEE_ID" HeaderText="Emp ID"/>
         <asp:BoundField DataField="EMPLOYEE_NAME" HeaderText="Emp Name"/>
         <asp:BoundField DataField="POSITION_DESCRIPTION" HeaderText="Position"/>
         <asp:BoundField DataField="SECTION_DESCRIPTION" HeaderText="Section"/>
         <asp:BoundField DataField="PROPOSED_TOPIC" HeaderText="Topic"/>
         <asp:BoundField DataField="METHOD_DEV_NAME" HeaderText="Method of Development"/>
         <asp:BoundField DataField="ESTIMATE_COST" HeaderText="Cost Estimation(USD)" />
         <asp:BoundField DataField="ROD_DESC" HeaderText="Reason of Dev"/>
         <asp:BoundField DataField="SCHEDULE_PLAN" HeaderText="Schedule Plan"/>
         <asp:BoundField DataField="ILP_CODE" HeaderText = "CODE" />

         <asp:TemplateField HeaderText="CODE">
            <ItemTemplate>
            <asp:LinkButton ID="linkAction" runat="server"
                CommandArgument = '<%# Eval("ILP_CODE")%>'                   
                Text = '<%# Bind("ILP_CODE")%>' OnClick = "ActionApproval"></asp:LinkButton>
            </ItemTemplate>
        </asp:TemplateField>

         </Columns>

    </asp:GridView>

这是我的aspx.cs代码

protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack & Request.IsAuthenticated)
        {
            BindData();
        }
    }



    private void BindData()
    {
        String magicNumber = Server.HtmlEncode(Request.Cookies[Constant.CookiesEmployeeId].Value);
        decimal nextAppEmpId = decimal.Parse(magicNumber);
        GridViewApproval.DataSource = (nextAppEmpId.Equals("null") || nextAppEmpId == 0) ? apDetail.GetIlpProcessPosition() : apEntity.getIlpProcessPositionNextEmpId(nextAppEmpId);

        GridViewApproval.DataBind();
    }

    protected void ActionApproval(object sender, EventArgs e)
    {
        LinkButton linkAction = (LinkButton)sender;
        Session["ILP_CODE"] = linkAction.CommandArgument;
        Response.Redirect("~/Web/ILP/ApprovalListDetail.aspx");
    }

    protected void OnDataBound(object sender, EventArgs e)
    {
        for (int i = GridViewApproval.Rows.Count - 1; i > 0; i--)
        {
            GridViewRow row = GridViewApproval.Rows[i];
            GridViewRow previousRow = GridViewApproval.Rows[i - 1];
            for (int j = 0; j < row.Cells.Count; j++)
            {
                if (j != 0)
                {
                if (row.Cells[j].Text == previousRow.Cells[j].Text)
                {
                    if (previousRow.Cells[j].RowSpan == 0)
                    {
                        if (row.Cells[j].RowSpan == 0)
                        {
                            previousRow.Cells[j].RowSpan += 2;
                        }
                        else
                        {
                            previousRow.Cells[j].RowSpan = row.Cells[j].RowSpan + 1;
                        }
                        row.Cells[j].Visible = false;
                    }
                }
                }

            }
        }

        string ilpCode = null, ilpCodeSave = null;

        for (int count = 0; count < GridViewApproval.Rows.Count; count++)
        {
            ilpCode = GridViewApproval.Rows[count].Cells[10].Text;
            if (!ilpCode.Equals(ilpCodeSave))
            {
                //GridViewApproval.Rows[count].Cells[10].Text = "Details";
            }
            ilpCodeSave = GridViewApproval.Rows[count].Cells[10].Text;

        }
    }
受保护的无效页面加载(对象发送方,事件参数e)
{
如果(!IsPostBack&Request.IsAuthenticated)
{
BindData();
}
}
私有void BindData()
{
字符串magicNumber=Server.HtmlEncode(Request.Cookies[Constant.CookiesEmployeeId].Value);
decimal-nextapempid=decimal.Parse(magicNumber);
GridViewApproval.DataSource=(nextAppEmpId.Equals(“null”)| | nextAppEmpId==0)?apDetail.GetIlpProcessPosition():apEntity.getIlpProcessPositionNextEmpId(nextAppEmpId);
GridViewApproval.DataBind();
}
受保护的void ActionApproval(对象发送者、事件参数e)
{
LinkButton linkAction=(LinkButton)发送方;
会话[“ILP_代码”]=linkAction.CommandArgument;
Response.Redirect(“~/Web/ILP/ApprovalListDetail.aspx”);
}
受保护的void OnDataBound(对象发送方,事件参数e)
{
对于(int i=GridViewApproval.Rows.Count-1;i>0;i--)
{
GridViewRow行=GridViewApproval.Rows[i];
GridViewRow previousRow=GridViewApproval.Rows[i-1];
对于(int j=0;j
这是我编译时的图像 以下是我能做的: 享受

//边界字段的循环
对于(int i=GridViewApproval.Rows.Count-1;i>0;i--)
{
GridViewRow行=GridViewApproval.Rows[i];
GridViewRow previousRow=GridViewApproval.Rows[i-1];
对于(int j=0;j0;i--)
{
GridViewRow行=GridViewApproval.Rows[i];
GridViewRow previousRow=GridViewApproval.Rows[i-1];
对于(int j=0;j
由于有多个名称和id,我必须合并此文件
//looping for boundfield
    for (int i = GridViewApproval.Rows.Count - 1; i > 0; i--)
        {
            GridViewRow row = GridViewApproval.Rows[i];
            GridViewRow previousRow = GridViewApproval.Rows[i - 1];
            for (int j = 0; j < row.Cells.Count & j != 5; j++)
            {
                if (row.Cells[j].Text == previousRow.Cells[j].Text)
                {
                    if (previousRow.Cells[j].RowSpan == 0)
                    {
                        if (row.Cells[j].RowSpan == 0)
                        {
                            previousRow.Cells[j].RowSpan += 2;
                        }
                        else
                        {
                            previousRow.Cells[j].RowSpan = row.Cells[j].RowSpan + 1;
                        }
                        row.Cells[j].Visible = false;
                    }
                }
            }
        }

        //Looping for TemplateField
        for (int i = GridViewApproval.Rows.Count - 1; i > 0; i--)
        {
            GridViewRow row = GridViewApproval.Rows[i];
            GridViewRow previousRow = GridViewApproval.Rows[i - 1];
            for (int j = 0; j < row.Cells.Count - 1; j++)
            {
                //Define what index on your template field cell that contain same value
                if (((LinkButton)row.Cells[9].FindControl("linkAction")).Text == ((LinkButton)previousRow.Cells[9].FindControl("linkAction")).Text)
                {
                    if (previousRow.Cells[9].RowSpan == 0)
                    {
                        if (row.Cells[9].RowSpan == 0)
                        {
                            previousRow.Cells[9].RowSpan += 2;
                        }
                        else
                        {
                            previousRow.Cells[9].RowSpan = row.Cells[9].RowSpan + 1;
                        }
                        row.Cells[9].Visible = false;
                    }
                }
            }
        }

        //This is to redefine again.
        for (int count = 0; count < GridViewApproval.Rows.Count; count++)
        {
            LinkButton lblprojectTest = GridViewApproval.Rows[count].Cells[9].FindControl("linkAction") as LinkButton;
            lblprojectTest.Text = "Details";
        }