C# 显示gridview,数据在gridview中出现两次。怎么删掉后边自动绑定部分
绑定数据之后变成刚学习Gridview,随便写个小代码测试一下。如何删掉后边重复部分请高手帮忙解决一下。代码如下protectedvoidPage_Load(object...
绑定数据之后变成
刚学习Gridview,随便写个小代码测试一下。如何删掉后边重复部分请高手帮忙解决一下。代码如下
protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { OleDbConnection conn = new OleDbConnection("Provider=OraOLEDB.Oracle.1;Data source=db_123;User ID =12345; Password=123");
//新建一个查询"select no as 学号,name as 姓名,class as 班级 from tab_student" OleDbDataAdapter adp2 = new OleDbDataAdapter("select no as 学号,name as 姓名,class as 班级 from tab_student", conn); DataSet ds2 = new DataSet(); conn.Open(); adp2.Fill(ds2); GridView2.DataSource = ds2; GridView2.DataKeyNames = new string[] { "学号" };
GridView2.DataBind(); conn.Close();
}}
</asp:GridView>
<asp:GridView ID="GridView2" runat="server" BackColor="White" BorderColor="#DEDFDE"
BorderStyle="None" BorderWidth="1px" CellPadding="4" ForeColor="Black" GridLines="Vertical"
Width="194px">
<AlternatingRowStyle BackColor="White" />
<FooterStyle BackColor="#CCCC99" />
<HeaderStyle BackColor="#6B696B" Font-Bold="True" ForeColor="White" />
<PagerStyle BackColor="#F7F7DE" ForeColor="Black" HorizontalAlign="Right" />
<RowStyle BackColor="#F7F7DE" />
<SelectedRowStyle BackColor="#CE5D5A" Font-Bold="True" ForeColor="White" />
<SortedAscendingCellStyle BackColor="#FBFBF2" />
<SortedAscendingHeaderStyle BackColor="#848384" />
<SortedDescendingCellStyle BackColor="#EAEAD3" />
<SortedDescendingHeaderStyle BackColor="#575357" />
<Columns>
<asp:BoundField DataField="学号" HeaderText="学号" />
<asp:BoundField DataField="姓名" HeaderText="姓名" />
<asp:BoundField DataField="班级" HeaderText="班级" />
<asp:CommandField ShowSelectButton="True" HeaderText="选择" />
<asp:CommandField ShowDeleteButton="true" HeaderText="删除" />
<asp:CommandField ShowEditButton="True" HeaderText="编辑" ButtonType="Button" />
</Columns>
</asp:GridView>
想把后边重复的表格数据删了。请高手大侠们多多提建议。拜谢了先。 展开
刚学习Gridview,随便写个小代码测试一下。如何删掉后边重复部分请高手帮忙解决一下。代码如下
protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { OleDbConnection conn = new OleDbConnection("Provider=OraOLEDB.Oracle.1;Data source=db_123;User ID =12345; Password=123");
//新建一个查询"select no as 学号,name as 姓名,class as 班级 from tab_student" OleDbDataAdapter adp2 = new OleDbDataAdapter("select no as 学号,name as 姓名,class as 班级 from tab_student", conn); DataSet ds2 = new DataSet(); conn.Open(); adp2.Fill(ds2); GridView2.DataSource = ds2; GridView2.DataKeyNames = new string[] { "学号" };
GridView2.DataBind(); conn.Close();
}}
</asp:GridView>
<asp:GridView ID="GridView2" runat="server" BackColor="White" BorderColor="#DEDFDE"
BorderStyle="None" BorderWidth="1px" CellPadding="4" ForeColor="Black" GridLines="Vertical"
Width="194px">
<AlternatingRowStyle BackColor="White" />
<FooterStyle BackColor="#CCCC99" />
<HeaderStyle BackColor="#6B696B" Font-Bold="True" ForeColor="White" />
<PagerStyle BackColor="#F7F7DE" ForeColor="Black" HorizontalAlign="Right" />
<RowStyle BackColor="#F7F7DE" />
<SelectedRowStyle BackColor="#CE5D5A" Font-Bold="True" ForeColor="White" />
<SortedAscendingCellStyle BackColor="#FBFBF2" />
<SortedAscendingHeaderStyle BackColor="#848384" />
<SortedDescendingCellStyle BackColor="#EAEAD3" />
<SortedDescendingHeaderStyle BackColor="#575357" />
<Columns>
<asp:BoundField DataField="学号" HeaderText="学号" />
<asp:BoundField DataField="姓名" HeaderText="姓名" />
<asp:BoundField DataField="班级" HeaderText="班级" />
<asp:CommandField ShowSelectButton="True" HeaderText="选择" />
<asp:CommandField ShowDeleteButton="true" HeaderText="删除" />
<asp:CommandField ShowEditButton="True" HeaderText="编辑" ButtonType="Button" />
</Columns>
</asp:GridView>
想把后边重复的表格数据删了。请高手大侠们多多提建议。拜谢了先。 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询