2011-08-12 71 views
0
<asp:GridView ID="gridInboxMessage" runat="server" 
      AutoGenerateColumns="False" 
      DataSourceID="LinqDataSource1"> 
    <Columns> 
     <asp:BoundField DataField="Title" HeaderText="title" ReadOnly="True" SortExpression="Title" /> 

     <asp:TemplateField HeaderText="Body" SortExpression="Body"> 
      <ItemTemplate> 
       <asp:Label ID="MyBody" runat="server" 
         Text='<%# TruncateText(Eval("Body"))%>'> 
       </asp:Label> 
      </ItemTemplate> 
     </asp:TemplateField> 

     <asp:TemplateField HeaderText="Sender"> 
      <ItemTemplate> 
       <asp:Label ID="MySender" runat="server" 
         Text='<%# GetSenderNameFromID(Eval("Sender"))%>'> 
       </asp:Label> 
      </ItemTemplate> 
     </asp:TemplateField> 

     <asp:TemplateField HeaderText="Date" SortExpression="Date1"> 
      <ItemTemplate> 
       <asp:Label ID="MyDate" runat="server" 
         Text='<%# DataBinder.Eval(Container.DataItem, "Date1", "{0:MMMM d yyy}")%>'> 
       </asp:Label> 
      </ItemTemplate> 
     </asp:TemplateField> 
    </Columns> 
</asp:GridView> 
<div id="FullBody"></div> 

代碼隱藏獲取內容的ItemTemplate

protected string TruncateText(object objBody) 
{ 
    string truncated = ""; 
    if (objBody != null) 
    { 
     truncated = objBody.ToString().Length > 50 ? 
      objBody.ToString().Substring(0, 47) + "..." : objBody.ToString(); 
    } 
    return truncated; 
} 

1.I想在

protected void gridInboxMessage_SelectedIndexChanged(object sender, EventArgs e) 
{ 
    GridViewRow row = gridInboxMessage.SelectedRow; 
    //i want show full body in div `fullBody` 
} 

如何訪問到身體表現出充分的身體在DIV fullBody

2.I甚至想要背景顏色爲黑色的行?

回答

0

爲了從你的代碼中訪問div背後,最簡單的方法是將您的div runat屬性設置爲true<div id="fullbody" runat="server"/>

然後在後面的代碼,您可以訪問它,就像任何其它的控制:fullbody.some_property = "";

而對於替代行背景顏色,您可以使用:<alternatingrowstyle backcolor="Black" />