我正在绑定一个gridview,看看下面的图片
但我想要的方式如下
下面是我的aspx代码
<asp:GridView ID="GridView2" runat="server" AutoGenerateColumns="False"
CellPadding="4" CssClass="mGrid" DataKeyNames="Sno"
EnableModelValidation="True" ForeColor="#333333" GridLines="None"
onrowediting="GridView2_RowEditing">
<AlternatingRowStyle BackColor="White" />
<Columns>
<asp:BoundField DataField="Block_Name" HeaderText="Block" />
<asp:BoundField DataField="Building_Name" HeaderText="Building" />
<asp:BoundField DataField="Sanctioned_DPR" HeaderText="Sanction Amt. (DPR)" />
<asp:BoundField DataField="Sanctioned_Contract"
HeaderText="Sanction Amt. (Contract)" />
<asp:CommandField ShowEditButton="True" />
</Columns>
<FooterStyle BackColor="#990000" Font-Bold="True" ForeColor="White" />
<HeaderStyle BackColor="#990000" Font-Bold="True" ForeColor="White" />
<PagerStyle BackColor="#FFCC66" ForeColor="#333333" HorizontalAlign="Center" />
<RowStyle BackColor="#FFFBD6" ForeColor="#333333" />
<SelectedRowStyle BackColor="#FFCC66" Font-Bold="True" ForeColor="Navy" />
</asp:GridView>
下面是我绑定gridview的代码文件代码
#region Select Building Budget
protected void Select_Building_Budget()
{
try
{
SqlCommand com = new SqlCommand("Select_Building_Budget_Grid_Bind", con);
com.CommandType = CommandType.StoredProcedure;
com.Parameters.Add("@SPMU_Id", SqlDbType.Int).Value = Convert.ToInt32(ddlStates.SelectedValue.ToString());
com.Parameters.Add("@SFTI_Id", SqlDbType.Int).Value = Convert.ToInt32(ddlSFTI.SelectedValue.ToString());
SqlDataAdapter sda = new SqlDataAdapter(com);
DataTable dt = new DataTable();
sda.Fill(dt);
if (dt.Rows.Count > 0)
{
GridView2.DataSource = dt;
GridView2.DataBind();
GridView2.Visible = true;
}
else
{
GridView2.Visible = false;
}
}
catch (Exception ex)
{
WebMsgBox.Show(ex.Message);
}
}
#endregion
这是我的sp
select mtblBuilding_Budget_Data.Sno,
mtblBuilding_Budget_Data.Building_Name,
mtblBuilding_Budget_Data.SFTI_Id,
mtblBuilding_Budget_Data.SPMU_Id,
mtblBuilding_Budget_Data.Sanctioned_DPR,
mtblBuilding_Budget_Data.Sanctioned_Contract,
mtblBlock.Block_Name
from mtblBuilding_Budget_Data
left JOIN mtblBlock on mtblBuilding_Budget_Data.Block_Id = mtblBlock.Block_Id
where mtblBuilding_Budget_Data.SPMU_Id = @SPMU_Id and
mtblBuilding_Budget_Data.SFTI_Id = @SFTI_Id
order BY mtblBuilding_Budget_Data.Sno desc
怎么做?