Hi Barath25,
I have created sample code which fullfill your requirement.
HTML
<div>
<asp:GridView ID="gvCUstomers" AutoGenerateColumns="false" runat="server">
<Columns>
<asp:TemplateField HeaderText="Message" ItemStyle-Width="130px">
<ItemTemplate>
<asp:Literal ID="litsort" Text='<%#Eval("Message").ToString().Length > 100 ? Eval("Message").ToString().Substring(0, 100) :Eval("Message").ToString()%>'
Visible="true" runat="server" />
<asp:Literal ID="litfull" Text='<%#Eval("Message")%>' Visible="false" runat="server" />
<asp:Button ID="btnexpand" Text="Expand" OnClick="Onexpand" Visible='<%#Eval("Message").ToString().Length > 100 ? true:false%>'
runat="server" />
<asp:Button ID="btncollapse" Text="collapse" OnClick="Oncollapse" Visible="false"
runat="server" />
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
</div>
C#
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
this.GetData();
}
}
private void GetData()
{
DataTable dt = new DataTable();
dt.Columns.Add("Message");
dt.Rows.Add("I need to display Message Column data from the database in such a way that i should display only first 100 charaters of the data in a message and i should have collapse or expand button at the end of the message. when i click on expand button the whole messages ");
dt.Rows.Add("I need to display Message Column d");
gvCUstomers.DataSource = dt;
gvCUstomers.DataBind();
}
protected void Onexpand(object sender, EventArgs e)
{
GridViewRow row = (sender as Button).NamingContainer as GridViewRow;
(row.FindControl("litsort") as Literal).Visible = false;
(row.FindControl("litfull") as Literal).Visible = true;
(row.FindControl("btnexpand") as Button).Visible = false;
(row.FindControl("btncollapse") as Button).Visible = true;
}
protected void Oncollapse(object sender, EventArgs e)
{
GridViewRow row = (sender as Button).NamingContainer as GridViewRow;
(row.FindControl("litsort") as Literal).Visible = true;
(row.FindControl("litfull") as Literal).Visible = false;
(row.FindControl("btnexpand") as Button).Visible = true;
(row.FindControl("btncollapse") as Button).Visible = false;
}
Screenshot