日期:2014-05-19  浏览次数:20465 次

gridview的问题~~~
gridview有两列~怎么在第一列   内容里面增加一个label     让该label读取数据库内容~     请前辈们指点   谢谢!我新手!请说的详细些     谢谢!最好能同时给出方法和源代码     拜谢!
gridview   label

------解决方案--------------------
<asp:GridView ID= "GridView1 " runat= "server " DataSourceID= "ObjectDataSource1 " AutoGenerateColumns= "False " >
<Columns>
<asp:TemplateField HeaderText= "姓名 ">
<ItemTemplate>
<asp:Label ID= "ID " Text= ' <%# Eval( "ID ") %> ' runat= "server " Visible= "false "> </asp:Label>
<asp:Label ID= "llr " Text= ' <%# Eval( "领料人 ") %> ' runat= "server "> </asp:Label>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
------解决方案--------------------
模板列
------解决方案--------------------
使用模板列可以实现
我share一个增加LinkButton的例子吧
------解决方案--------------------
<asp:GridView ID= "gvUseBusRecord " runat= "server " CellPadding= "4 " ForeColor= "#333333 " GridLines= "None " AutoGenerateColumns= "False " CssClass= "officedoc " OnRowDataBound= "gvUseBusRecord_RowDataBound " AllowPaging= "True " AllowSorting= "True " OnPageIndexChanging= "gvUseBusRecord_PageIndexChanging " OnSorting= "gvUseBusRecord_Sorting " OnRowDeleting= "gvUseBusRecord_RowDeleting ">
<FooterStyle BackColor= "#507CD1 " Font-Bold= "True " ForeColor= "White " />
<EmptyDataTemplate>
没有找到符合条件的数据
</EmptyDataTemplate>
<Columns>
<asp:BoundField DataField= "UserBusDate " HeaderText= "用车时间 " SortExpression= "UserBusDate " DataFormatString= "{0:yyyy年MM月dd日} " />
<asp:BoundField DataField= "RecordID " HeaderText= "记录编号 " Visible= "False " />
<asp:BoundField DataField= "PersonName " HeaderText= "用车人 " SortExpression= "PersonName " />
<asp:BoundField DataField= "StartPos " HeaderText= "起点 " SortExpression= "StartPos " />
<asp:BoundField DataField= "DestPos " HeaderText= "终点 " SortExpression= "DestPos " />
<asp:BoundField DataField= "Status " HeaderText= "状态 " SortExpression= "Status " />
<asp:BoundField DataField= "BusID " HeaderText= "派车情况 " SortExpression= "BusID "/>
<asp:CommandField DeleteText= "撤销 " ShowDeleteButton= "True " />
<asp:TemplateField>
<ItemTemplate>
<asp:LinkButton runat= "server " id= "lbView " Text= "查看 "> </asp:LinkButton>
</ItemTemplate>
</asp:TemplateField>
</Columns>
<RowStyle BackColor= "#EFF3FB " />
<EditRowStyle BackColor= &