Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7013681
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T22:25:21+00:00 2026-05-27T22:25:21+00:00

I moved a Datalist Control on an aspx page on to a usercontrol and

  • 0

I moved a Datalist Control on an aspx page on to a usercontrol and referenced it to the aspx page. In the process, I also moved the source code for the datalist( ItemDataBound and Display methods). I am using a “Datatable” as the source for the Datalist population. after I move the control in to a user control, it throws me a NullReference right when i try to assign the datatable as a source to the datalist.

public partial class Controls_ProductSpecifications : System.Web.UI.UserControl
{
    protected void Page_Load(object sender, EventArgs e)
    {
        //no code yet here...
    }

    public void DisplaySpecifications(SearchResultItem sri,bool IsMobilePage)
    {
        List<Category> breadcrumbCategories = sri.BreadcrumbCategories;
        Category templateCat =  breadcrumbCategories[breadcrumbCategories.Count - 1];

        ParametricColumnSortOrder customDimSortOrder = null;
        int rowPosition = 0; // manufacturer, product category, rohs
        bool isUnclassified = false;

        // -- get the sorted parametric list from database
        if (templateCat.Id.ToString() != null)
            customDimSortOrder = new ParametricColumnSortOrder(Convert.ToInt64(templateCat.Id), false, true);

        //List<ParametricAttributeGroup> plist = sri.ParametricDimensions;
        if (breadcrumbCategories[0].Name == "Unclassified")
        {
            ////if (breadcrumbCategories.Count > 1)
            ////{
            ////    //---{ Create an unclassifed attribute group } 
            ////    ParametricAttributeGroup pag = new ParametricAttributeGroup(breadcrumbCategories[0].Id, breadcrumbCategories[0].Name);
            ////    pag.ParametricAttributes.Add(new ParametricAttribute(breadcrumbCategories[1].Id, breadcrumbCategories[1].Name));
            ////    plist.Add(pag);
            ////}
        }

        var dt = new DataTable();
        dt.Columns.Add("Dimension");
        dt.Columns.Add("DimensionID");
        dt.Columns.Add("Attribute");
        dt.Columns.Add("AttributeID");
        dt.Columns.Add("CheckBox");
        dt.Columns.Add("CheckBoxState");

        DataRow dr;

        List<ParametricAttributeGroup> translatedAttGrp = sri.ParametricDimensions;

        LanguageDataAccess.GetTranslatedAttributes(translatedAttGrp, Language.CurrentLanguageCulture);

        foreach (ParametricAttributeGroup attributeGroup in translatedAttGrp)
        {
            ParametricAttribute attribute = attributeGroup.ParametricAttributes[0];

            dr = dt.NewRow();
            dr["Dimension"] = attributeGroup.Name;
            dr["DimensionID"] = attributeGroup.Id;
            dr["Attribute"] = attribute.Value;
            dr["AttributeID"] = attribute.Id;
            dr["CheckBox"] = "false";

            string grpname = attributeGroup.Name;
            // -- get the original name instead of the translated name for comparision --
            if (attributeGroup is LocalizationParametricAttributeGroup)
            {
                grpname = ((LocalizationParametricAttributeGroup)attributeGroup).OriginalName;
            }

            if (grpname == "Manufacturer")
            {
                dr["Dimension"] = Resources.lblManufacturer;
                dr["CheckBoxState"] = "0";
                dt.Rows.InsertAt(dr, rowPosition);
                rowPosition++;
            }
            else if (grpname == "Product Category")
            {
                // -- don't show product category if this product is under Unclassified --

                isUnclassified = breadcrumbCategories.Any(cat => cat.Name == Resources.MyMouser.lblUnclassified);

                if (!isUnclassified)
                {
                    dr["Dimension"] = attributeGroup.Name;
                    dr["Attribute"] = templateCat.Name;
                    dr["AttributeID"] = templateCat.Id;
                    dr["CheckBoxState"] = "0";
                    dt.Rows.InsertAt(dr, rowPosition);
                    rowPosition++;
                }
            }
            else if (grpname == "Unclassified")
            {
                dr["Dimension"] = Resources.lblUnclassified;
                dr["CheckBoxState"] = "0";
                dt.Rows.InsertAt(dr, rowPosition);
                rowPosition++;
            }
            else if (grpname == "RoHS - Mouser")
            {
                dr["Dimension"] = Resources.MyMouser.litHeaderRoHS;
                dr["Attribute"] = SearchHelper.CreateRoHSLabel(sri,sri.EnRoHSStatus, isUnclassified,IsMobilePage);
                dt.Rows.InsertAt(dr, rowPosition);
                rowPosition++;
            }
            else if (grpname == "Standard Pack Qty")
            {
                dr["Dimension"] = Resources.MyMouser.lblfactrPakcQty;
                dt.Rows.Add(dr);
            }
            else
            {
                dt.Rows.Add(dr);
            }
        }

        // -- sort the visiable fields --
        if (customDimSortOrder != null)
        {
            for (int dimSortIndex = 0; dimSortIndex < customDimSortOrder.Count; dimSortIndex++)
            {
                foreach (DataRow oldRow in dt.Rows)
                {
                    if (customDimSortOrder.AllKeys[dimSortIndex] == oldRow["DimensionID"].ToString())
                    {
                        dr = dt.NewRow();
                        dr["Dimension"] = oldRow["Dimension"];
                        dr["DimensionID"] = oldRow["DimensionID"];
                        dr["Attribute"] = oldRow["Attribute"];
                        dr["AttributeID"] = oldRow["AttributeID"];
                        dr["CheckBoxState"] = "0";
                        dt.Rows.Remove(oldRow);
                        dt.Rows.InsertAt(dr, rowPosition);
                        rowPosition++;
                        break;
                    }
                }
            }
        }

        //aliases information - shawn weng
        if (sri.Aliases != "")
        {
            dr = dt.NewRow();
            dr["Dimension"] = Resources.MyMouser.lblpartaliases;
            dr["DimensionID"] = 0;
            dr["Attribute"] = sri.Aliases;
            dr["AttributeID"] = 0;
            dr["CheckBox"] = "false";
            dt.Rows.Add(dr);
        }
        try
        {
            DataList dl1 = (DataList) this.FindControl("dlspec");
            dl1.DataSource = dt;
            dl1.DataBind();
        }
        catch (Exception ex)
        {
            throw;
        }

    }

    protected void dlspec_ItemDataBound(object sender, DataListItemEventArgs e)
    {
        if ((e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
            && e.Item.DataItem != null)
        {
            // -- checkbox --
            var ck = e.Item.FindControl("FindSimilarCheckbox") as CheckBox;
            if (ck != null)
            {
                ck.ID = ck.Text;
                ck.Text = "";

                var lbldim = e.Item.FindControl("lblDimension") as Label;
                if (lbldim != null)
                {
                    if (lbldim.Text.Contains(Resources.MyMouser.lblManufacturer) || lbldim.Text.Contains(Resources.MyMouser.lblProductCategory))
                    {
                        ck.Checked = true;
                    }
                    if (lbldim.Text.Contains(Resources.MyMouser.lblfactrPakcQty))
                    {

                        string PackageQtylnk = "<a href=JAVASCRIPT:OpenFactoryQty();>" + Resources.MyMouser.lblfactrPakcQty + "</a>";
                        lbldim.Text = string.Format(PackageQtylnk);
                        lbldim.CssClass = "factorypackage";
                    }
                }
            }
        }
    }
}

here is the ascx page markup:

<%@ Control Language="C#" AutoEventWireup="true"       CodeBehind="ProductSpecifications.ascx.cs" Inherits="MouserWeb.Controls.Controls_ProductSpecifications" %>
 <asp:DataList ID="dlspec" runat="server" GridLines="Vertical" OnItemDataBound="dlspec_ItemDataBound">
<FooterStyle BackColor="#CCCCCC" />
<AlternatingItemStyle CssClass="alt-grey" />
<SelectedItemStyle BackColor="#000099" Font-Bold="True" ForeColor="White" />
<HeaderStyle BackColor="Black" Font-Bold="True" ForeColor="White" />
<ItemTemplate>
    <table width="550px">
    <tr>
        <td class="leftcol">
        <asp:Label ID="lblDimension" runat="server" Text='<%# Eval("Dimension") %>'></asp:Label>:
        </td>
        <td class="ProductDetailData">
        <asp:Label ID="lblName" runat="server" Text='<%# Eval("Attribute") %>'></asp:Label>
        </td>
        <td class="find-similar">
        <asp:CheckBox ID="FindSimilarCheckbox" runat="server" Checked='<%# Eval("CheckBox")=="true"? true:false %>'
            Text='<%# Eval("AttributeID") %>' Visible='<%# Eval("CheckBoxState")=="0"? true:false %>' />
        <%--<input name='<%# Eval("DimensionID") %>' id='<%# Eval("DimensionID") %>' type="checkbox" checked='<%# Eval("CheckBox")=="true"? true:false %>' />--%>
        </td>
    </tr>
    </table>
</ItemTemplate>
</asp:DataList>

Does anything seem wrong?? Please let me know if i can provide more information(code) about this…Thanks in advance for your valuable help

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T22:25:22+00:00Added an answer on May 27, 2026 at 10:25 pm

    I don’t see where you call DisplaySpecifications(...) to DataBind the DataList?

    protected void Page_Load(object sender, EventArgs e)
    {
        //no code yet here...
        if(!Page.IsPostBack)
        {
            DisplaySpecifications(...);
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I moved a Datalist Control on an aspx page on to a usercontrol and
I had recently moved a DataList control in to a UserControl and referenced it
This is my DataList code , I define a table in headertemplate and close
Recently moved from svn to git, pardon my newbie question. In our release process,
I am using a DataList along with paging with the help of a PagedDataSource.
I moved my blog from example.com to example.com/blog. I now have a splash page
I want to select the index id of datalist my code is protected void
Moved from a Web Application to a Web Site, began moving code over... and
I moved a file using git mv . Now I would like to do
Moved a bunch of databases from sql server 2000 to 2008. One of the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.