troubleshooting Question

Want the databinding to work on an empty dataset.

Avatar of mathieu_cupryk
mathieu_cuprykFlag for Canada asked on
ASP.NET
9 Comments3 Solutions456 ViewsLast Modified:
I have the following and in code snippet what I am trying to do is remove the sqldatasource

protected void BindDropDownList()
        {
            DataList1.DataSource = GetBinaryImagesByUserId.GetBinaryImages(strUsrId);
            DataList1.DataBind();
            // Select * into Dataset it will fail if empty.
            GridView1.DataSource = GetBinaryImagesByUserId.GetBinaryImages(strUsrId);
            GridView1.DataBind();

        }
How can we duplicate so it works like the below.
  <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:LocalSqlServer %>"
            SelectCommand="SELECT * FROM [aspnet_Images]"></asp:SqlDataSource>
        <br />
        <asp:DataList Visible="false" ID="DataList1" runat="server" DataKeyField="ImagesId" DataSourceID="SqlDataSource1" CellSpacing="15" EnableViewState="false"
            RepeatColumns="4" OnItemDataBound="DataList1_ItemDataBound">
            <ItemTemplate>
                <cc1:RbmBinaryImage ID="RbmBinaryImage2" runat="server" DisplayThumbnail="True"  EmptyImageUrl="images/NoPhoto.JPG" /><br />
                <asp:Literal runat="server" ID="literal1" Text='<%# Eval("ImagesTitle") %>'></asp:Literal><br />
            </ItemTemplate>
        </asp:DataList></div>
       
        <div>
            <asp:GridView ID="GridView2" runat="server" AutoGenerateColumns="False" DataKeyNames="ImagseId" DataSourceID="SqlDataSource1">
                <Columns>
                    <asp:BoundField DataField="ImagesId" HeaderText="ImagesId" InsertVisible="False" ReadOnly="True"
                        SortExpression="ImagesId" />
                    <asp:BoundField DataField="ImagesTitle" HeaderText="ImagesTitle" SortExpression="ImagesTitle" />
                    <asp:TemplateField HeaderText="BinaryImage">
                        <ItemTemplate>
                            <cc1:RbmBinaryImage ID="RbmBinaryImage2" runat="server"  ImageContent='<%# Eval("ImagesContent") %>'  EmptyImageUrl="images/NoPhoto.JPG" />
                        </ItemTemplate>
                    </asp:TemplateField>
                </Columns>
            </asp:GridView>
This works I want t oremove the datasource.


<asp:DataList Visible="false" ID="DataList1" runat="server"
        DataKeyField="ImagesId"
        CellSpacing="15" EnableViewState="false" RepeatColumns="4"
        OnItemDataBound="DataList1_ItemDataBound">
        <ItemTemplate>
            <cc1:RbmBinaryImage ID="RbmBinaryImage2" runat="server" DisplayThumbnail="True" EmptyImageUrl="~/images/NoPhoto.JPG" /><br />
            <asp:Literal runat="server" ID="literal1" Text='<%# Eval("ImagesTitle") %>'></asp:Literal><br />
        </ItemTemplate>
    </asp:DataList>
</div>
 
<div>
    <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False">
        <Columns>
            <asp:BoundField DataField="ImagesId" HeaderText="ImagesId" InsertVisible="False" ReadOnly="True"
                SortExpression="ImagesId" />
            <asp:BoundField DataField="ImagesTitle" HeaderText="ImagesTitle" SortExpression="ImagesTitle" />
            <asp:TemplateField HeaderText="BinaryImage">
                <ItemTemplate>
                    <cc1:RbmBinaryImage id="RbmBinaryImage2" runat="server" imagecontent='<%# Eval("ImagesContent") %>'
                        emptyimageurl="~/Images/NoPhoto.JPG" />
                </ItemTemplate>
            </asp:TemplateField>
        </Columns>
    </asp:GridView>
This does not work when the dataset is empty.
-------------------------------------------------------------------------------
 
 
 
 
 
 
 
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:TestDBConnectionString %>"
            SelectCommand="SELECT * FROM [ImageTest]"></asp:SqlDataSource>
        <br />
        <asp:DataList Visible="false" ID="DataList1" runat="server" DataKeyField="ImageId" DataSourceID="SqlDataSource1" CellSpacing="15" EnableViewState="false"
            RepeatColumns="4" OnItemDataBound="DataList1_ItemDataBound">
            <ItemTemplate>
                <Rbm:RbmBinaryImage ID="RbmBinaryImage2" runat="server" DisplayThumbnail="True"  EmptyImageUrl="~/images/NoPhoto.JPG" /><br />
                <asp:Literal runat="server" ID="literal1" Text='<%# Eval("ImageTitle") %>'></asp:Literal><br />
            </ItemTemplate>
        </asp:DataList></div>
        
        <div>
            <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" DataKeyNames="ImageId" DataSourceID="SqlDataSource1">
                <Columns>
                    <asp:BoundField DataField="ImageId" HeaderText="ImageId" InsertVisible="False" ReadOnly="True"
                        SortExpression="ImageId" />
                    <asp:BoundField DataField="ImageTitle" HeaderText="ImageTitle" SortExpression="ImageTitle" />
                    <asp:TemplateField HeaderText="BinaryImage">
                        <ItemTemplate>
                            <Rbm:RbmBinaryImage ID="RbmBinaryImage2" runat="server"  ImageContent='<%# Eval("ImageContent") %>'  EmptyImageUrl="~/images/NoPhoto.JPG" />
                        </ItemTemplate>
                    </asp:TemplateField>
                </Columns>
            </asp:GridView>
        </div>
ASKER CERTIFIED SOLUTION
M3mph15

Our community of experts have been thoroughly vetted for their expertise and industry experience.

Join our community to see this answer!
Unlock 3 Answers and 9 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 3 Answers and 9 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros