locked
how to use split function in my grid item template RRS feed

  • Question

  • User-102500655 posted

    hi every one i have a question hope fully its simple

    i have a grid view i want to use split function in its edit template can i and how?

    here is the code

    <ItemTemplate>
                    <asp:Label ID="lblfname" runat="server" Text='<%# Bind("Name")%>'></asp:Label>
    </ItemTemplate>
    now i don't want to show full name instead i want to split the name as i can do in code behind like
    Name.Split('_');
    and then want to show part after _ in my GridView
              
    Friday, September 16, 2011 1:49 AM

Answers

  • User-20777992 posted
    Sorry for the delayed reply!!!
    Here is the line you need to put!!!

    <asp:Label ID="lblfname" runat="server"
    Text='<%# System.Text.RegularExpressions.Regex.Split(Eval("Name").ToString()," ")[1] %>'></asp:Label>

      Cheers!!!

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Friday, September 16, 2011 5:55 AM

All replies

  • User-20777992 posted

    Try This!!!

    <asp:Label ID="lblfname" runat="server" Text='<%Convert.ToString(#Eval("Name")).Split('_')[1]%>'></asp:Label>
    Friday, September 16, 2011 2:03 AM
  • User-366017857 posted

    While reading the values from DB get the name only using following and your code will work

    SUBSTRING(Name, CHARINDEX('_',Name)+ 1,LEN(Name))as Name


    It will give you only name just bind to your lable

    Friday, September 16, 2011 2:05 AM
  • User-102500655 posted

    <asp:Label ID="lblfname" runat="server" Text='<%Convert.ToString(#Eval("Name")).Split('_')[1]%>'</asp:Label>

    gives no error but insted but it show name as '> where this is not part of my name.its showing value after % any idea??

    Friday, September 16, 2011 3:18 AM
  • User-102500655 posted

    While reading the values from DB get the name only using following and your code will work

    SUBSTRING(Name, CHARINDEX('_',Name)+ 1,LEN(Name))as Name

    i dont want to use this becoz i need that full name too in the same grid view..

    Friday, September 16, 2011 3:21 AM
  • User-20777992 posted

    Pl. change the position of '#' in the line as follows.

    <asp:Label ID="lblfname" runat="server" Text='<%#Convert.ToString(Eval("Name")).Split('_')[1]%>'</asp:Label>

    Let me know in case of any queries!!!

    Friday, September 16, 2011 3:21 AM
  • User-102500655 posted

    on this change it start giving error when i skip the part of skip and keep only with tostring it shows nothing..when i remove tostring and use split it show same result '> does not matter if i use [0] or [1] it gvs same answer '>

    now what to do??

    Friday, September 16, 2011 3:36 AM
  • User-20777992 posted

    Pl. try this. The problem is because I am replying from my cell phone I cant test it at my end!!!

    <asp:Label ID="lblfname" runat="server" Text='<%#Eval("Name").ToString().Split('_')[1]%>'</asp:Label>

    This should work!!! Pl. Let me know if it does not!!!

    Friday, September 16, 2011 3:46 AM
  • User-102500655 posted

    Still not working :-(

    Friday, September 16, 2011 5:10 AM
  • User-20777992 posted
    Sorry for the delayed reply!!!
    Here is the line you need to put!!!

    <asp:Label ID="lblfname" runat="server"
    Text='<%# System.Text.RegularExpressions.Regex.Split(Eval("Name").ToString()," ")[1] %>'></asp:Label>

      Cheers!!!

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Friday, September 16, 2011 5:55 AM
  • User-102500655 posted

    Thanks it woks :-)

    Friday, September 16, 2011 6:08 AM