<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>
Code Behind
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 want that in
protected void gridInboxMessage_SelectedIndexChanged(object sender, EventArgs e)
{
GridViewRow row = gridInboxMessage.SelectedRow;
//i want show full body in div `fullBody`
}
how can access to body to show full body in div fullBody
2.I want even rows with background color is black?
In order to access
divfrom your code behind, the easiest way is to setrunatproperty of your div totruei.e.<div id="fullbody" runat="server"/>Then in your code behind, you can access it just like anyother control:
fullbody.some_property = "";And for alternative row background color you can use:
<alternatingrowstyle backcolor="Black" />