locked
How Bind Data In MRV Code39 Bar Code Fonts RRS feed

  • Question

  • User2033107836 posted

    Hello

    I used this code to bind data to gridview in asp.net 2.0 C#

    My aspx page

     <asp:GridView ID="GridView1" runat="server" AllowPaging="True" AutoGenerateColumns="False"
                                    Font-Bold="True" >
                                    <Columns>                                 
                                         <asp:TemplateField HeaderText="Item Code">
                                            <ItemTemplate>
                                                <asp:Label ID="L1" runat="server" Text='<%# Eval("ItemCode") %>'></asp:Label>
                                            </ItemTemplate>
                                            <ItemStyle Width="150px" ForeColor="#00C0C0" />
                                            <ControlStyle Width="50px" />
                                        </asp:TemplateField>
                                        <asp:TemplateField HeaderText="Item Name">
                                            <ItemTemplate>
                                                <asp:Label ID="L2" runat="server" Text='<%# Eval("Item_Name") %>'></asp:Label>
                                            </ItemTemplate>
                                            <ItemStyle Width="150px" ForeColor="Red" />
                                        </asp:TemplateField>                                  
                                      
                                    </Columns>
                                    <HeaderStyle BackColor="#3AC0F2" ForeColor="White" />
                                </asp:GridView>

    My C# code

     DataTable dt = new DataTable();
            SqlConnection zcon1 = new SqlConnection(ConfigurationManager.ConnectionStrings["iConnectionString"].ConnectionString);
            zcon1.Open();
            SqlCommand zcmd1 = new SqlCommand("select ItemCode,ItemName from Table1 ", zcon1);
            SqlDataAdapter zada1 = new SqlDataAdapter(zcmd1);
            zcmd1.CommandTimeout = 9000; ;
            zada1.Fill(zdt1);
            GridView1.DataSource = dt;
            GridView1.DataBind();

    It shows result set like this

    ItemCode ItemName
    B136A Apple
    C345K Mango
    L121M Banana

    I want to add third column as Bar code Column to create bar code image like this below using MRV Code39extMA 

    https://www.dafont.com/mrv-code39extma.font

    How to do so using asp.net 2.0 C#

    Thanks in advance

    Tuesday, November 7, 2017 11:32 AM

Answers

  • User-335504541 posted

    Hi asp.ambur,

    First install the font your download.

    Then create a new column in the gridview for bar code, set font-name to the label which display the code.

       <asp:GridView ID="GridView1" runat="server" AllowPaging="True" AutoGenerateColumns="False"
                    Font-Bold="True">
                    <Columns>
                        <asp:TemplateField HeaderText="Item Code">
                            <ItemTemplate>
                                <asp:Label ID="L1" runat="server" Text='<%# Eval("ItemCode") %>'></asp:Label>
                            </ItemTemplate>
                            <ItemStyle Width="150px" ForeColor="#00C0C0" />
                            <ControlStyle Width="50px" />
                        </asp:TemplateField>
                        <asp:TemplateField HeaderText="Item Name">
                            <ItemTemplate>
                                <asp:Label ID="L2" runat="server" Text='<%# Eval("ItemName") %>'></asp:Label>
                            </ItemTemplate>
                            <ItemStyle Width="150px" ForeColor="Red" />
                        </asp:TemplateField>
                        <asp:TemplateField HeaderText="Bar Code">
                            <ItemTemplate>
                                <asp:Label ID="L3" runat="server" Text='<%# Eval("ItemCode") %>' Width="150px" Font-Names="mrv code39extma"></asp:Label>
                            </ItemTemplate>
                            <ItemStyle Width="150px" />
                        </asp:TemplateField>
                    </Columns>
                    <HeaderStyle BackColor="#3AC0F2" ForeColor="White" />
                </asp:GridView>

    And the result is:

    Best Regards,

    Billy

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, November 8, 2017 2:30 AM
  • User-335504541 posted

    Hi asp.ambur,

    You could try to set HorizontalAlign to center and set Font-Bold to false.

    For example:

    <asp:TemplateField HeaderText="Bar Code">
                            <ItemTemplate>
                                <asp:Label ID="L3" runat="server" Text='<%# Eval("ItemCode") %>' Width="150px" Font-Bold="false" Font-Size="XX-Large" Font-Names="mrv code39extma"></asp:Label>
                            </ItemTemplate>
                            <ItemStyle Width="150px" HorizontalAlign="Center" />
                        </asp:TemplateField>

    And the result is:

    Best Regards,

    Billy

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, November 9, 2017 8:58 AM

All replies

  • User-335504541 posted

    Hi asp.ambur,

    First install the font your download.

    Then create a new column in the gridview for bar code, set font-name to the label which display the code.

       <asp:GridView ID="GridView1" runat="server" AllowPaging="True" AutoGenerateColumns="False"
                    Font-Bold="True">
                    <Columns>
                        <asp:TemplateField HeaderText="Item Code">
                            <ItemTemplate>
                                <asp:Label ID="L1" runat="server" Text='<%# Eval("ItemCode") %>'></asp:Label>
                            </ItemTemplate>
                            <ItemStyle Width="150px" ForeColor="#00C0C0" />
                            <ControlStyle Width="50px" />
                        </asp:TemplateField>
                        <asp:TemplateField HeaderText="Item Name">
                            <ItemTemplate>
                                <asp:Label ID="L2" runat="server" Text='<%# Eval("ItemName") %>'></asp:Label>
                            </ItemTemplate>
                            <ItemStyle Width="150px" ForeColor="Red" />
                        </asp:TemplateField>
                        <asp:TemplateField HeaderText="Bar Code">
                            <ItemTemplate>
                                <asp:Label ID="L3" runat="server" Text='<%# Eval("ItemCode") %>' Width="150px" Font-Names="mrv code39extma"></asp:Label>
                            </ItemTemplate>
                            <ItemStyle Width="150px" />
                        </asp:TemplateField>
                    </Columns>
                    <HeaderStyle BackColor="#3AC0F2" ForeColor="White" />
                </asp:GridView>

    And the result is:

    Best Regards,

    Billy

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, November 8, 2017 2:30 AM
  • User2033107836 posted

    Thanks For Your Reply

    1) After taking print of gridivew if i scan i barcode it will return data right?

    2) Its looking too dark can we reduce font size?

    Thanks

    Wednesday, November 8, 2017 9:27 AM
  • User-335504541 posted

    Hi asp.ambur,

    1) After taking print of gridivew if i scan i barcode it will return data right?

    I think it depends on your scanner.

    2) Its looking too dark can we reduce font size?

    Yes, for example:

    <asp:Label ID="L3" runat="server" Text='<%# Eval("ItemCode") %>' Width="150px" Font-Size="XX-Large" Font-Names="mrv code39extma"></asp:Label>
    

    Best Regards,

    Billy

    Wednesday, November 8, 2017 12:23 PM
  • User2033107836 posted

    Hello

    Its showing again very dark bold but i want like this so that in print it will come center in box

    I want bar code to be look like this 

    http://i65.tinypic.com/2j4a73s.png

    Thursday, November 9, 2017 5:44 AM
  • User-335504541 posted

    Hi asp.ambur,

    You could try to set HorizontalAlign to center and set Font-Bold to false.

    For example:

    <asp:TemplateField HeaderText="Bar Code">
                            <ItemTemplate>
                                <asp:Label ID="L3" runat="server" Text='<%# Eval("ItemCode") %>' Width="150px" Font-Bold="false" Font-Size="XX-Large" Font-Names="mrv code39extma"></asp:Label>
                            </ItemTemplate>
                            <ItemStyle Width="150px" HorizontalAlign="Center" />
                        </asp:TemplateField>

    And the result is:

    Best Regards,

    Billy

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, November 9, 2017 8:58 AM
  • User2033107836 posted

    Hello

    Why its not reading data..? Is any problem?

    Thursday, November 9, 2017 9:01 AM