Click here to Skip to main content
15,891,780 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
Hi,
I have a GridView with some values which are read from database.
I want to show them in persian.
This is my code :

C#
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" 
            DataKeyNames="GroupId" DataSourceID="SqlDataSource1">
         <Columns>
             <asp:BoundField DataField="GroupId" HeaderText="GroupId" ReadOnly="True" 
                 SortExpression="GroupId" />
             <asp:BoundField DataField="<%=ToFarsi('ParentGroupId')%>"
                 HeaderText="ParentGroupId" 
                 SortExpression="ParentGroupId" />
             <asp:BoundField DataField="GroupName" HeaderText="GroupName" 
                 SortExpression="GroupName" />
         </Columns>
     </asp:GridView>

<asp:SqlDataSource ID="SqlDataSource1" runat="server" 
            ConnectionString="<%$ ConnectionStrings:dbtestConnectionString2 %>" 
            SelectCommand="SELECT * FROM [T_group]"></asp:SqlDataSource>


And my method :

public static string ToFarsi(string str)
   {
       string vInt = "1234567890";
       char[] mystring = str.ToCharArray(0, str.Length);
       var newStr = string.Empty;
       for (var i = 0; i <= (mystring.Length - 1); i++)
           if (vInt.IndexOf(mystring[i]) == -1)
               newStr += mystring[i];
           else
               newStr += ((char)((int)mystring[i] + 1728));
       return newStr;
   }



This is the error :
A field or property with the name '<%=ToFarsi('ParentGroupId')%>' was not found on the selected data source.
Posted
Updated 8-Feb-12 13:21pm
v4

hi
The Data Filed values will check the Selected Column names which you are going to bind there is no column in this ID "<%=ToFarsi('ParentGroupId')%>"
thats why its listing that error

I think you have to figure out some other methods to Conversion now you are trying to Convert it from the Datagrid DataField itself...
 
Share this answer
 
Comments
Tech Code Freak 8-Feb-12 12:07pm    
5up!
Tony Tom.k 9-Feb-12 0:28am    
thnx dude
I already answered this question about "Eastern Arabic Numerals", but Persian variant is a bit different, as described here:

http://en.wikipedia.org/wiki/Eastern_Arabic_numerals[^].

So the implementation could be a bit more complex but the idea is basically the same.

So, please see my past solution for Eastern Arabic:
Arabic number problem in asp.net[^].

My code is similar to your ToFarsi, just check it up.

You may need to fix this implementation to fix the Persian numerals. I could not figure out the mapping between Unicode code points and Persian variant of numerals, but it's possible that the mapping is not just the shift (ordering can be non-linear). Please use http://unicode.org/[^] to find out.

—SA
 
Share this answer
 
v2
Comments
Tech Code Freak 8-Feb-12 12:07pm    
5up!
Sergey Alexandrovich Kryukov 8-Feb-12 21:02pm    
Thank you,
--SA
Convert the ParentGroupID BoundField to TemplateField and you should be fine
ASP.NET
<asp:templatefield headertext="ParentGroupId">
     <itemtemplate>
            <asp:label id="Label1" runat="server" text='<%# ToFarsi(Eval("parentid").ToString()) %>'>
            </asp:label>
     </itemtemplate>
</asp:templatefield>


Please mark the solution as accepted it you like it.
 
Share this answer
 
v4

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900