初学者请教C#代码

娃哈哈真好喝01 2010-09-24 01:32:30
根据在TextBox1中的输入,点击查询后,连接数据库,从数据库中取出:品名,规格型号,单位,等。数据库已连接上。
输入的数据,在数据库中查询到的各项有可能不止一个,请大家教一下怎么用GridView实现?



<asp:TextBox ID="TextBox1" runat="server" ></asp:TextBox>
<asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="查询" />


<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="true"
CssClass="tableBorder0" CellPadding="2" CellSpacing="1" BorderWidth="0"
Width="1500" onrowdatabound="GridView1_RowDataBound"
ShowFooter="True" Visible="True"
onselectedindexchanged="GridView1_SelectedIndexChanged">
<Columns>
<asp:BoundField DataField="TD005" HeaderText="品名" ItemStyle-HorizontalAlign="Center" />
<asp:BoundField DataField="TD006" HeaderText="规格型号" ItemStyle-HorizontalAlign="Center"/>
<asp:BoundField DataField="TD010" HeaderText="单位" ItemStyle-HorizontalAlign="Center"/>
<asp:BoundField DataField="TD008" HeaderText="数量" ItemStyle-HorizontalAlign="Center"/>
<asp:BoundField DataField="TD013" HeaderText="要求交货日期" ItemStyle-HorizontalAlign="Center"/>
<asp:TemplateField ItemStyle-Width="60" HeaderText="生管同意日期" />
<asp:BoundField DataField="TD027" HeaderText="机号" ItemStyle-HorizontalAlign="Center"/>

</Columns>
</asp:GridView>
...全文
308 23 打赏 收藏 转发到动态 举报
写回复
用AI写文章
23 条回复
切换为时间正序
请发表友善的回复…
发表回复
poppinH 2010-09-25
  • 打赏
  • 举报
回复
[Quote=引用 8 楼 majic2008 的回复:]
C# code

string sql="select * from table where 1=1";
if(txt.Text!="")
{
string condition=this.txt.Text.Tostring();
sql+= " and txt like '%"+condition+"%'";
}
DataSet ds = new D……
[/Quote]

UP..楼主的GV已经有看到字段的功能了.只要把数据按照要求绑定就好了..这个代码放在CS页面中就没问题了.DataField="TD005" 这引号里必须对应的是你数据表中的字段名称.
lx13133013781 2010-09-25
  • 打赏
  • 举报
回复
唉............。。。。。。。。。。。。
wilensky 2010-09-25
  • 打赏
  • 举报
回复
又见要代码的。。。。。。
liue_0612 2010-09-25
  • 打赏
  • 举报
回复
唉............。。。。。。。。。。。。
LinChangPeng 2010-09-25
  • 打赏
  • 举报
回复
上百度找
kevin87923 2010-09-25
  • 打赏
  • 举报
回复
就是在查询按钮里根据条件查询出的数据,对GridView重新绑定就可以了
exiori 2010-09-25
  • 打赏
  • 举报
回复
这个不是基础吗
zm81499259 2010-09-25
  • 打赏
  • 举报
回复
GridView1.DataSource = ;
GridView1.DataBind();
super1021love 2010-09-25
  • 打赏
  • 举报
回复
先写个模糊查询、然后查出来的数据放到集合中、然后把该集合作为返回值返回、然后用gridview的datasource绑定就好了呀
lqkankan 2010-09-25
  • 打赏
  • 举报
回复
jf

复内容太短了!
Lxpd 2010-09-25
  • 打赏
  • 举报
回复
GridView1.DataSource = dt;
GridView1.DataBind();
村长_乐 2010-09-25
  • 打赏
  • 举报
回复
gridview.DataSource =用sql语句查询出来的结果集
gridview.DataBind();
如果只要一条数据top1
beg200710 2010-09-25
  • 打赏
  • 举报
回复
网上很多源码 拿来就能用
kofkyo 2010-09-25
  • 打赏
  • 举报
回复
[Quote=引用 7 楼 hizhl168 的回复:]
全部 代码 都写全了。。。不知道还要怎么具体
[/Quote]
楼主应该去看书,而不是在这里问
majic2008 2010-09-25
  • 打赏
  • 举报
回复
[Quote=引用 8 楼 majic2008 的回复:]
C# code

string sql="select * from table where 1=1";
if(txt.Text!="")
{
string condition=this.txt.Text.Tostring();
sql+= " and txt like '%"+condition+"%'";
}
DataSet ds = new D……
[/Quote]
把注释的恢复
majic2008 2010-09-25
  • 打赏
  • 举报
回复

string sql="select * from table where 1=1";
if(txt.Text!="")
{
string condition=this.txt.Text.Tostring();
sql+= " and txt like '%"+condition+"%'";
}
DataSet ds = new DataSet();
//SqlHelper.FillDataSet(ds, SqlHelper.GetCmd(sql));
DataTable table = SqlHelper.GetDataTable(sql);

this.gridview.DataSource = ds;
this.gridview.DataBind();
hizhl168 2010-09-25
  • 打赏
  • 举报
回复
全部 代码 都写全了。。。不知道还要怎么具体
juxianxiang 2010-09-25
  • 打赏
  • 举报
回复
[Quote=引用 4 楼 dada52020 的回复:]
页面上这个写

<ItemTemplate>
//里面放数据
<tr>
<td>
<%#Eval("列名") %>
</td>
<td>
<%#Eval("列名") %>
</td>

........
</tr>

</ItemTemplate>

cs代码中

GridView1.DataSource ……
[/Quote]
很具体。
  • 打赏
  • 举报
回复
具体的呢
哒哒 2010-09-24
  • 打赏
  • 举报
回复
页面上这个写

<ItemTemplate>
//里面放数据
<tr>
<td>
<%#Eval("列名") %>
</td>
<td>
<%#Eval("列名") %>
</td>

........
</tr>

</ItemTemplate>

cs代码中

GridView1.DataSource =你查询出来的数据组
GridView1.DataBind();
例如:
OldHomePhoneDataList.DataSource = memberManager.MemberHomePhoneSelect(asc);
this.OldHomePhoneDataList.DataBind();
加载更多回复(3)

62,271

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术交流专区
javascript云原生 企业社区
社区管理员
  • ASP.NET
  • .Net开发者社区
  • R小R
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

.NET 社区是一个围绕开源 .NET 的开放、热情、创新、包容的技术社区。社区致力于为广大 .NET 爱好者提供一个良好的知识共享、协同互助的 .NET 技术交流环境。我们尊重不同意见,支持健康理性的辩论和互动,反对歧视和攻击。

希望和大家一起共同营造一个活跃、友好的社区氛围。

试试用AI创作助手写篇文章吧