====DataGrid的问题。UP者有分。======

Proyang 2004-07-28 02:45:53
<asp:datagrid id="DataGrid1" runat="server" AllowPaging="True" Width="100%" BorderColor="#E7E7FF"
BorderStyle="None" BorderWidth="1px" BackColor="White" CellPadding="3" GridLines="Horizontal" AutoGenerateColumns="False"
Font-Size="10pt">
<SelectedItemStyle Font-Bold="True" ForeColor="#F7F7F7" BackColor="#738A9C"></SelectedItemStyle>
<AlternatingItemStyle BackColor="#F7F7F7"></AlternatingItemStyle>
<ItemStyle ForeColor="#4A3C8C" BackColor="#E7E7FF"></ItemStyle>
<HeaderStyle Font-Bold="True" ForeColor="#F7F7F7" BackColor="#4A3C8C"></HeaderStyle>
<FooterStyle ForeColor="#4A3C8C" BackColor="#B5C7DE"></FooterStyle>
<Columns>
<asp:TemplateColumn>
<HeaderTemplate>
<FONT face="宋体">文件名</FONT>
</HeaderTemplate>
<asp:TemplateColumn>
<HeaderTemplate>
<FONT face="宋体">上传时间</FONT>
</HeaderTemplate>
<ItemTemplate>
<asp:Label id="Label1" runat="server">
<%# DataBinder.Eval(Container.DataItem, "上传时间") %>
</asp:Label>
</ItemTemplate>
</asp:TemplateColumn>

。。。。
private void DataGrid1_ItemDataBound(object sender, System.Web.UI.WebControls.DataGridItemEventArgs e)
{

Control coll;
if((e.Item.ItemType==ListItemType.Item)||(e.Item.ItemType==ListItemType.AlternatingItem))
{

//Response.Write("trtr<br/>");
//Response.Write(e.Item.Cells.Count);
coll = e.Item.FindControl("Label1");
Label temp = (Label) coll;
Response.Write(temp.Text);
}

}

为什么Response.Write(temp.Text); 什么也不出来呢???
...全文
83 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
Proyang 2004-07-28
  • 打赏
  • 举报
回复
hehe,谢谢CMIC(大象)。
原来我犯了一个这么愚昧的错误。
CMIC 2004-07-28
  • 打赏
  • 举报
回复
<asp:Label id="Label1" runat="server">
<%# DataBinder.Eval(Container.DataItem, "上传时间") %>
</asp:Label>
--------------------------------------------------------------
<asp:Label id="Label1" runat="server" Text=<%# DataBinder.Eval(Container.DataItem, "上传时间") %>>
</asp:Label>
adminyao 2004-07-28
  • 打赏
  • 举报
回复
UP
yyf_321 2004-07-28
  • 打赏
  • 举报
回复
不明白,但为了分先up一下
realzhaoxin 2004-07-28
  • 打赏
  • 举报
回复
up
using System; using System.Data; using System.Data.SqlClient; using System.Configuration; using System.Web; using System.Web.Security; using System.Web.UI; using System.Web.UI.WebControls; using System.Web.UI.WebControls.WebParts; using System.Web.UI.HtmlControls; public partial class _Default : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { LoginAcc.LoginCheck(); if (!Page.IsPostBack) { DataBind(); } } void DataBind() { //string str = "select NewsId,Title,AddTime,ViewCounter from ViewTable order by AddTime desc"; SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString); conn.Open(); SqlCommand cmd = new SqlCommand("up_GetDetilNews", conn); cmd.CommandType = CommandType.StoredProcedure; DataSet ds = new DataSet(); SqlDataAdapter da = new SqlDataAdapter(cmd); da.Fill(ds,"result"); GridView1.DataSource = ds.Tables["result"]; GridView1.DataBind(); } protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e) { //GridView1.PageIndex = e.NewPageIndex; GridView theGrid = sender as GridView; // refer to the GridView int newPageIndex = 0; if (-2 == e.NewPageIndex) { // when click the "GO" Button TextBox txtNewPageIndex = null; //GridViewRow pagerRow = theGrid.Controls[0].Controls[theGrid.Controls[0].Controls.Count - 1] as GridViewRow; // refer to PagerTemplate GridViewRow pagerRow = theGrid.BottomPagerRow; //GridView较DataGrid提供了更多的API,获取页块可以使用BottomPagerRow 或者TopPagerRow,当然还增加了HeaderRow和FooterRow //updated at 2006年6月21日3:15:33 if (null != pagerRow) { txtNewPageIndex = pagerRow.FindControl("txtNewPageIndex") as TextBox; // refer to the TextBox with the NewPageIndex value } if (null != txtNewPageIndex) { newPageIndex = int.Parse(txtNewPageIndex.Text) - 1; // get the NewPageIndex } } else { // when click the first, last, previous and next Button newPageIndex = e.NewPageIndex; } // check to prevent form the NewPageIndex out of the range newPageIndex = newPageIndex < 0 ? 0 : newPageIndex; newPageIndex = newPageIndex >= theGrid.PageCount ? theGrid.PageCount - 1 : newPageIndex; // specify the NewPageIndex theGrid.PageIndex = newPageIndex; // rebind the control // in this case of retrieving the data using the xxxDataSoucr control, // just do nothing, because the asp.net engine binds the data automatically // 别忘了重新绑定 DataBind(); } protected void GridView1_RowDeleting(object sender, GridViewDeleteEventArgs e) { string strId = (GridView1.DataKeys[e.RowIndex].Value).ToString(); string delStr = "delete from ViewTable where NewsId=" + strId; DbUtil.DbHelper.ExecSqlNonQuerry(delStr); DataBind(); MyUtil.CsHelper.ExecJS("删除成功!", this); } }

62,047

社区成员

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

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

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

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