7

我有一个网格视图

        <asp:BoundField DataField="UnusedTicketAmount" HeaderText="UnusedTicketAmount" />
        <asp:BoundField DataField="ddlUnusedAmount" HeaderText="ddlUnusedAmount" />
        <asp:BoundField DataField="AirlinePenality" HeaderText="AirlinePenality" />
        <asp:BoundField DataField="ddlAirlinePenality" HeaderText="ddlAirlinePenality" />
        <asp:BoundField DataField="NetRefundProcess" HeaderText="NetRefundProcess" />
        <asp:BoundField DataField="ddlNetRefundProcess" HeaderText="ddlNetRefundProcess" />
        <asp:BoundField DataField="RefundableCommission" HeaderText="RefundableCommission" />
        <asp:BoundField DataField="ddlRefundableCommission" HeaderText="ddlRefundableCommission" />
        <asp:BoundField DataField="CouponRefunded" HeaderText="CouponRefunded" />
        <asp:BoundField DataField="RefundType" HeaderText="RefundType" /> 

在这个gridview中,我想将airlinepenality和ddlairlinepanelity添加到一列中,我该如何做到这一点提前谢谢

4

3 回答 3

11

您可以像这样创建一个模板字段并绑定两个字段。

<asp:TemplateField HeaderText="Airlinepenality"   SortExpression="ddlAirlinePenality">
<ItemTemplate>
    <asp:Label ID="Label1" runat="server" Text='<%#Eval("AirlinePenality")+ " " + Eval("ddlAirlinePenality")%>' ></asp:Label>
</ItemTemplate>

于 2013-04-02T14:28:48.603 回答
1

你正在使用Bound fieldwe can merge two columns by TemplateField只有,所以更好you can merge that two columns in your query

尝试如下...

询问:

SELECT UnusedTicketAmount, ddlUnusedAmount, 
cast(1.25 as varchar) + ' ' + cast(172813.99 as varchar) as AirlinePenality,
NetRefundProcess,ddlNetRefundProcess,RefundableCommission
ddlRefundableCommission,CouponRefunded,RefundType

网格视图

<asp:BoundField DataField="UnusedTicketAmount" HeaderText="UnusedTicketAmount" />
<asp:BoundField DataField="ddlUnusedAmount" HeaderText="ddlUnusedAmount" />
<asp:BoundField DataField="AirlinePenality" HeaderText="AirlinePenality" />
<asp:BoundField DataField="NetRefundProcess" HeaderText="NetRefundProcess" />
<asp:BoundField DataField="ddlNetRefundProcess" HeaderText="ddlNetRefundProcess" />
<asp:BoundField DataField="RefundableCommission" HeaderText="RefundableCommission" />
<asp:BoundField DataField="ddlRefundableCommission" HeaderText="ddlRefundableCommission" />
<asp:BoundField DataField="CouponRefunded" HeaderText="CouponRefunded" />
<asp:BoundField DataField="RefundType" HeaderText="RefundType" /> 
于 2013-04-02T14:34:20.363 回答
1

假设您要合并网格的最后三列,那么您也可以使用以下代码:

  protected void grdAirTicketList_RowDataBound(object sender, GridViewRowEventArgs e)
  {
      if (e.Row.RowType == DataControlRowType.Header)
      {
          e.Row.Cells[8].Visible = false;
          e.Row.Cells[7].Visible = false;
          e.Row.Cells[6].Attributes.Add("colspan", "3");
      }
  }

这意味着您的名为“CouponRefunded”和“RefundType”的列将不可见,而 colspan 3 将显示“ddlRefundableCommission”。

于 2013-07-18T10:20:09.167 回答