Sign In| Join
Get Help:Ask a Question in our Forums|Report a Bug|More Help Resources
Last post Oct 06, 2012 02:38 AM by vicky1
Member
32 Points
349 Posts
Oct 05, 2012 05:01 PM|LINK
Hi all,
Hope doing well,
sir i have one gridview which has linkbutton in itemplate there i am fetching email id like vickyatgaya@gmail.com.
and i want that when it should fetch the text it should remove @gmail.com from the text and show only this vickyatgaya
here is my code:
<asp:GridView ID="GrvDraft" runat="server" AutoGenerateColumns="False" CellPadding="4" Width="100%" CssClass="Grid" onrowcommand="GrvDraft_RowCommand" DataKeyNames="id" OnRowDataBound="GrvDraft_RowDataBound" GridLines="None" EmptyDataText="No items saved"> <Columns> <asp:TemplateField ItemStyle-CssClass="grvdraftid"> <HeaderTemplate> <asp:checkbox id="chkHeader1" runat="server"/> </HeaderTemplate> <ItemTemplate> <asp:CheckBox ID="chkChild1" runat="server" ClientIDMode="Static"/> </ItemTemplate> <HeaderStyle HorizontalAlign="Left" /> <ItemStyle HorizontalAlign="Left" /> </asp:TemplateField> <asp:TemplateField ItemStyle-CssClass="grvdraftimg1"> <ItemTemplate> <%# Eval("status") %> </ItemTemplate> </asp:TemplateField> <asp:TemplateField ItemStyle-CssClass="grvdrafteid"> <ItemTemplate> <asp:LinkButton ID="LinkBtn" runat="server" Text='<%#Eval("eid") %>' ForeColor="Black" Font-Underline="false" CommandName="Date" CommandArgument='<%#Eval("id") %>'></asp:LinkButton> <%-- <%# Eval("eid") %>--%> </ItemTemplate> </asp:TemplateField> </Columns> <HeaderStyle BackColor="#292929" Font-Bold="True" /> </asp:GridView>
please help me.
thanks in advance.
Contributor
5514 Points
810 Posts
Oct 05, 2012 05:37 PM|LINK
protected void GrvDraft_RowDataBound(object sender, GridViewRowEventArgs e) { if (e.Row.RowType == DataControlRowType.DataRow) { LinkButton LinkBtn = (LinkButton)e.Row.FindControl("LinkBtn"); LinkBtn.Text = LinkBtn.Text.Split('@')[0]; //or if (LinkBtn.Text.Contains("@")) LinkBtn.Text = LinkBtn.Text.Substring(0, LinkBtn.Text.IndexOf('@')); } }
Hope this helps...
Oct 06, 2012 02:38 AM|LINK
Hi Vipin,
thanks dude it's working for me.
thanks alot. i am marking it as answer.
vicky1
Member
32 Points
349 Posts
How to remove specific text in item template in gridview?
Oct 05, 2012 05:01 PM|LINK
Hi all,
Hope doing well,
sir i have one gridview which has linkbutton in itemplate there i am fetching email id like vickyatgaya@gmail.com.
and i want that when it should fetch the text it should remove @gmail.com from the text and show only this vickyatgaya
here is my code:
<asp:GridView ID="GrvDraft" runat="server" AutoGenerateColumns="False"
CellPadding="4" Width="100%" CssClass="Grid"
onrowcommand="GrvDraft_RowCommand" DataKeyNames="id" OnRowDataBound="GrvDraft_RowDataBound" GridLines="None" EmptyDataText="No items saved">
<Columns>
<asp:TemplateField ItemStyle-CssClass="grvdraftid">
<HeaderTemplate>
<asp:checkbox id="chkHeader1" runat="server"/>
</HeaderTemplate>
<ItemTemplate>
<asp:CheckBox ID="chkChild1" runat="server" ClientIDMode="Static"/>
</ItemTemplate>
<HeaderStyle HorizontalAlign="Left" />
<ItemStyle HorizontalAlign="Left" />
</asp:TemplateField>
<asp:TemplateField ItemStyle-CssClass="grvdraftimg1">
<ItemTemplate>
<%# Eval("status") %>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField ItemStyle-CssClass="grvdrafteid">
<ItemTemplate>
<asp:LinkButton ID="LinkBtn" runat="server" Text='<%#Eval("eid") %>' ForeColor="Black" Font-Underline="false" CommandName="Date" CommandArgument='<%#Eval("id") %>'></asp:LinkButton>
<%-- <%# Eval("eid") %>--%>
</ItemTemplate>
</asp:TemplateField>
</Columns>
<HeaderStyle BackColor="#292929" Font-Bold="True" />
</asp:GridView>
please help me.
thanks in advance.
Vipindas
Contributor
5514 Points
810 Posts
Re: How to remove specific text in item template in gridview?
Oct 05, 2012 05:37 PM|LINK
protected void GrvDraft_RowDataBound(object sender, GridViewRowEventArgs e) { if (e.Row.RowType == DataControlRowType.DataRow) { LinkButton LinkBtn = (LinkButton)e.Row.FindControl("LinkBtn"); LinkBtn.Text = LinkBtn.Text.Split('@')[0]; //or if (LinkBtn.Text.Contains("@")) LinkBtn.Text = LinkBtn.Text.Substring(0, LinkBtn.Text.IndexOf('@')); } }Hope this helps...
vicky1
Member
32 Points
349 Posts
Re: How to remove specific text in item template in gridview?
Oct 06, 2012 02:38 AM|LINK
Hi Vipin,
thanks dude it's working for me.
thanks alot. i am marking it as answer.