c#中怎么添加代码实现查询数据,在窗体里以表格形式现实查询的 结果
要添加什么控件(具体代码),以表格形式显示查询的结果,具体的所有代码,大侠赐教!gridview怎么用,我要代码完整代码?具体的gridview怎么用,只要那段的代码就可...
要添加什么控件(具体代码),以表格形式显示查询的结果,具体的所有代码,大侠赐教!
gridview怎么用,我要代码完整代码? 具体的 gridview怎么用,只要那段的 代码就 可以了
this.dataGridView1.DataSource = ds; 但是运行后这里this.dataGridView1.DataBindings有错误,
说什么错误 1 只有 assignment、call、increment、decrement 和 new 对象表达式可用作语句. 怎么回事呢? 展开
gridview怎么用,我要代码完整代码? 具体的 gridview怎么用,只要那段的 代码就 可以了
this.dataGridView1.DataSource = ds; 但是运行后这里this.dataGridView1.DataBindings有错误,
说什么错误 1 只有 assignment、call、increment、decrement 和 new 对象表达式可用作语句. 怎么回事呢? 展开
2个回答
展开全部
是VS2003就用datagrid,05就是gridview,08就用datagridview。你是哪个版本?
SqlConnection con= new SqlConnection("server=serverName;database=数据库;uid=sa;pwd=密码;");
con.Open();
DataTable dt = new DataTable();
string sql="select * from 表";
SqlDataAdapter da = new SqlDataAdapter(sql,con);
da.Fill(dt);
this.gridview1.DataSource=dt;
this.gridview1.DataBind();///
不要最后一句。。你是window form程序就不要这句
SqlConnection con= new SqlConnection("server=serverName;database=数据库;uid=sa;pwd=密码;");
con.Open();
DataTable dt = new DataTable();
string sql="select * from 表";
SqlDataAdapter da = new SqlDataAdapter(sql,con);
da.Fill(dt);
this.gridview1.DataSource=dt;
this.gridview1.DataBind();///
不要最后一句。。你是window form程序就不要这句
展开全部
我的建议是你去看看视频教程,ado.net数据操作,对你的帮助很大。
前台:
<asp:GridView ID="gvlist" runat="server" AllowPaging="True" AutoGenerateColumns="False" CellPadding="0" DataKeyNames="new_Id" GridLines="Horizontal" Width="95%" OnPageIndexChanging="gvlist_PageIndexChanging" ShowFooter="True" PageSize="2">
<FooterStyle CssClass="hsctrbiaoti" />
<EmptyDataRowStyle BackColor="#56B8E7" />
<Columns>
<asp:TemplateField HeaderText="序号">
<ItemStyle HorizontalAlign="Center" Width="5%" Wrap="False" />
<ItemTemplate>
<asp:Label ID="Labelid" runat="server" Text="<%# this.gvlist.PageIndex * this.gvlist.PageSize + this.gvlist.Rows.Count + 1%>"></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:HyperLinkField DataNavigateUrlFields="new_ID" DataNavigateUrlFormatString="News_Detail.aspx?id={0}"
DataTextField="new_Title" DataTextFormatString="{0:c}" HeaderText="主标题" Target="_blank">
<ItemStyle HorizontalAlign="Left" Width="30%" Wrap="False" VerticalAlign="Middle" />
</asp:HyperLinkField>
<asp:BoundField DataField="pb_type" HeaderText="栏目">
<ItemStyle HorizontalAlign="Center" Width="10%" Wrap="False" VerticalAlign="Middle" />
</asp:BoundField>
<asp:BoundField DataField="opname" HeaderText="编辑人">
<ItemStyle HorizontalAlign="Center" Width="15%" Wrap="False" VerticalAlign="Middle" />
</asp:BoundField>
<asp:BoundField DataField="pb_isvalid" HeaderText="状态">
<ItemStyle HorizontalAlign="Center" Width="7%" Wrap="False" VerticalAlign="Middle" />
</asp:BoundField>
<asp:TemplateField HeaderText="修改">
<ItemStyle Width="5%" HorizontalAlign="Center" VerticalAlign="Middle" />
<ItemTemplate>
<asp:LinkButton ID="LinkButton1" runat="server" PostBackUrl='<%#"News_Update.aspx?id="+Eval("new_ID") %>'>修改</asp:LinkButton>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField>
<HeaderTemplate>
<asp:LinkButton ID="btnAll" runat="server" OnClick="btnAll_Click">全选</asp:LinkButton>
</HeaderTemplate>
<FooterTemplate>
<asp:LinkButton ID="btnDel_All" runat="server" OnClick="btnDel_All_Click">删除所选</asp:LinkButton>
</FooterTemplate>
<ItemTemplate>
<asp:CheckBox ID="checkbx" runat="server" />
</ItemTemplate>
<ItemStyle HorizontalAlign="Center" VerticalAlign="Middle" Width="8%" />
<HeaderStyle Width="6%" />
</asp:TemplateField>
</Columns>
<PagerTemplate>
<table>
<tr>
<td style="color: #0067be; text-align: center;">
<asp:Label ID="lblindex" runat="server"><% ="第 " + (gvlist.PageIndex + 1) + " 页"%></asp:Label>
<asp:Label ID="lblall" runat="server"><% ="共有 " + gvlist.PageCount + " 页"%></asp:Label>
[
<asp:LinkButton ID="lbnfirst" ForeColor="#0067BE" runat="server" OnClick="lbnfirst_Click">首 页</asp:LinkButton>
|
<asp:LinkButton ID="lbnprev" ForeColor="#0067BE" runat="server" OnClick="lbnprev_Click">上一页</asp:LinkButton>
|
<asp:LinkButton ID="lbnnext" ForeColor="#0067BE" runat="server" OnClick="lbnnext_Click">下一页</asp:LinkButton>
|
<asp:LinkButton ID="lbnend" ForeColor="#0067BE" runat="server" OnClick="lbnend_Click">尾 页</asp:LinkButton>
] 到第<span class="wz19"><asp:TextBox ID="TbPgIndex" runat="server" Height="11px"
MaxLength="5" Style="text-align: center" Width="20px" Wrap="False"></asp:TextBox></span>页
<asp:ImageButton ID="IbnGo" runat="server" Height="18px" ImageAlign="Middle" ImageUrl="../BK_images/GO.jpg"
OnClick="IbnGo_Click" Width="36px" />
</td>
</tr>
</table>
</PagerTemplate>
<RowStyle CssClass="hsctr01" Height="22px" Wrap="False" />
<EmptyDataTemplate>
<table style="width: 100%; height: 25px">
<tr>
<td>
没有相关数据!
</td>
</tr>
</table>
</EmptyDataTemplate>
<PagerStyle CssClass="hscline01" Height="24px" HorizontalAlign="Center" />
<HeaderStyle CssClass="hsctrbiaoti" HorizontalAlign="Center" />
<AlternatingRowStyle BackColor="#D3EFFD" Height="22px" />
</asp:GridView>
后台:数据绑定。。。。
前台:
<asp:GridView ID="gvlist" runat="server" AllowPaging="True" AutoGenerateColumns="False" CellPadding="0" DataKeyNames="new_Id" GridLines="Horizontal" Width="95%" OnPageIndexChanging="gvlist_PageIndexChanging" ShowFooter="True" PageSize="2">
<FooterStyle CssClass="hsctrbiaoti" />
<EmptyDataRowStyle BackColor="#56B8E7" />
<Columns>
<asp:TemplateField HeaderText="序号">
<ItemStyle HorizontalAlign="Center" Width="5%" Wrap="False" />
<ItemTemplate>
<asp:Label ID="Labelid" runat="server" Text="<%# this.gvlist.PageIndex * this.gvlist.PageSize + this.gvlist.Rows.Count + 1%>"></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:HyperLinkField DataNavigateUrlFields="new_ID" DataNavigateUrlFormatString="News_Detail.aspx?id={0}"
DataTextField="new_Title" DataTextFormatString="{0:c}" HeaderText="主标题" Target="_blank">
<ItemStyle HorizontalAlign="Left" Width="30%" Wrap="False" VerticalAlign="Middle" />
</asp:HyperLinkField>
<asp:BoundField DataField="pb_type" HeaderText="栏目">
<ItemStyle HorizontalAlign="Center" Width="10%" Wrap="False" VerticalAlign="Middle" />
</asp:BoundField>
<asp:BoundField DataField="opname" HeaderText="编辑人">
<ItemStyle HorizontalAlign="Center" Width="15%" Wrap="False" VerticalAlign="Middle" />
</asp:BoundField>
<asp:BoundField DataField="pb_isvalid" HeaderText="状态">
<ItemStyle HorizontalAlign="Center" Width="7%" Wrap="False" VerticalAlign="Middle" />
</asp:BoundField>
<asp:TemplateField HeaderText="修改">
<ItemStyle Width="5%" HorizontalAlign="Center" VerticalAlign="Middle" />
<ItemTemplate>
<asp:LinkButton ID="LinkButton1" runat="server" PostBackUrl='<%#"News_Update.aspx?id="+Eval("new_ID") %>'>修改</asp:LinkButton>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField>
<HeaderTemplate>
<asp:LinkButton ID="btnAll" runat="server" OnClick="btnAll_Click">全选</asp:LinkButton>
</HeaderTemplate>
<FooterTemplate>
<asp:LinkButton ID="btnDel_All" runat="server" OnClick="btnDel_All_Click">删除所选</asp:LinkButton>
</FooterTemplate>
<ItemTemplate>
<asp:CheckBox ID="checkbx" runat="server" />
</ItemTemplate>
<ItemStyle HorizontalAlign="Center" VerticalAlign="Middle" Width="8%" />
<HeaderStyle Width="6%" />
</asp:TemplateField>
</Columns>
<PagerTemplate>
<table>
<tr>
<td style="color: #0067be; text-align: center;">
<asp:Label ID="lblindex" runat="server"><% ="第 " + (gvlist.PageIndex + 1) + " 页"%></asp:Label>
<asp:Label ID="lblall" runat="server"><% ="共有 " + gvlist.PageCount + " 页"%></asp:Label>
[
<asp:LinkButton ID="lbnfirst" ForeColor="#0067BE" runat="server" OnClick="lbnfirst_Click">首 页</asp:LinkButton>
|
<asp:LinkButton ID="lbnprev" ForeColor="#0067BE" runat="server" OnClick="lbnprev_Click">上一页</asp:LinkButton>
|
<asp:LinkButton ID="lbnnext" ForeColor="#0067BE" runat="server" OnClick="lbnnext_Click">下一页</asp:LinkButton>
|
<asp:LinkButton ID="lbnend" ForeColor="#0067BE" runat="server" OnClick="lbnend_Click">尾 页</asp:LinkButton>
] 到第<span class="wz19"><asp:TextBox ID="TbPgIndex" runat="server" Height="11px"
MaxLength="5" Style="text-align: center" Width="20px" Wrap="False"></asp:TextBox></span>页
<asp:ImageButton ID="IbnGo" runat="server" Height="18px" ImageAlign="Middle" ImageUrl="../BK_images/GO.jpg"
OnClick="IbnGo_Click" Width="36px" />
</td>
</tr>
</table>
</PagerTemplate>
<RowStyle CssClass="hsctr01" Height="22px" Wrap="False" />
<EmptyDataTemplate>
<table style="width: 100%; height: 25px">
<tr>
<td>
没有相关数据!
</td>
</tr>
</table>
</EmptyDataTemplate>
<PagerStyle CssClass="hscline01" Height="24px" HorizontalAlign="Center" />
<HeaderStyle CssClass="hsctrbiaoti" HorizontalAlign="Center" />
<AlternatingRowStyle BackColor="#D3EFFD" Height="22px" />
</asp:GridView>
后台:数据绑定。。。。
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询