We help IT Professionals succeed at work.

Unable to pass datarepeater value into a sqldatasource parameter

1,298 Views
Last Modified: 2013-11-25
I have a datarepeater that has a nested datagrid within it's Itemtemplate.  I need to pass the RecordID value from my repeater into my sqldatasource that my datagrid will be using.    

I have the following sqldatasource in within the repeaters Itemtemplate.  
<asp:SqlDataSource ID="SqlDataSource1" runat="server"
            ConnectionString="Data Source=DRSNYDER2003;Initial Catalog=UHG;Integrated Security=True"
            ProviderName="System.Data.SqlClient"
           
            SelectCommand="SELECT [BCID], [fkScan_Status], [ScanDate], [ScannedBy] FROM [Scan_BarCode] WHERE ([fkRecordID] = @fkID)">
           
            <SelectParameters>
            <asp:Parameter Name="fkID" Type="String" DefaultValue="<%# Eval("RecordID")%>" />
            </SelectParameters>
        </asp:SqlDataSource>


The problem is with the Parameter, when I try to set the DefaultValue to <%# Eval("RecordID")%>.  I've tried all sorts of syntaxes here and haven't been able to get it to wo

Here is the error I receive:
Description: An error occurred during the parsing of a resource required to service this request. Please review the following specific parse error details and modify your source file appropriately.

Parser Error Message: Literal content ('<asp:Parameter Name="fkID" Type="String" DefaultValue="') is not allowed within a 'System.Web.UI.WebControls.ParameterCollection'.

Source Error:


Line 97:            
Line 98:             <SelectParameters>
Line 99:             <asp:Parameter Name="fkID" Type="String" DefaultValue="<%# Eval("RecordID")%>" />
Line 100:            </SelectParameters>
Line 101:        </asp:SqlDataSource>
 

<asp:Repeater id="cdcatalog" runat="server"> 
<HeaderTemplate>
<table border="1" width="300px">
<tr>
<th class="tdText" style="font-weight:bold;" align="left">RecordID</th>
<th class="tdText" style="font-weight:bold;" align="left">Scans Expected</th>
<th class="tdText" style="font-weight:bold;" align="left">Scans Completed</th>
<th class="tdText" style="font-weight:bold;" align="left">Record Status</th>
</tr>
</HeaderTemplate> 
<ItemTemplate> 
<tr>
    <td class="tdText"><%# Eval("RecordID")%></td>
    <td class="tdText"><%# Eval("Scans Expected")%></td>
    <td class="tdText"><%# Eval("Scans Completed")%></td>
    <td class="tdText"><%# Eval("Record Status")%></td>
    <td class="tdText">
        <asp:LinkButton ID="Button1" Text="View Scans" runat="server" />
        <obout:Flyout ID="Flyout1" runat="server" AttachTo="Button1" Position="MIDDLE_RIGHT" Align="TOP">
            <div style="width:200px;background-color:lightblue">
                   
        <asp:SqlDataSource ID="SqlDataSource1" runat="server" 
            ConnectionString="Data Source=DRSNYDER2003;Initial Catalog=UHG;Integrated Security=True" 
            ProviderName="System.Data.SqlClient" 
            
            SelectCommand="SELECT [BCID], [fkScan_Status], [ScanDate], [ScannedBy] FROM [Scan_BarCode] WHERE ([fkRecordID] = @fkID)"> 
            
            <SelectParameters>
            <asp:Parameter Name="fkID" Type="String" DefaultValue="<%# Eval("RecordID")%>" />
            </SelectParameters>
        </asp:SqlDataSource>
 
        <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" 
            DataKeyNames="BCID" DataSourceID="SqlDataSource1">
            <Columns>
                <asp:BoundField DataField="BCID" HeaderText="BCID" ReadOnly="True" 
                    SortExpression="BCID" />
                <asp:BoundField DataField="fkScan_Status" HeaderText="fkScan_Status" 
                    SortExpression="fkScan_Status" />
                <asp:BoundField DataField="ScanDate" HeaderText="ScanDate" 
                    SortExpression="ScanDate" />
                <asp:BoundField DataField="ScannedBy" HeaderText="ScannedBy" 
                    SortExpression="ScannedBy" />
            </Columns>
        </asp:GridView> 
      
            </div>
        </obout:Flyout> 
    </td>
</tr> 

</ItemTemplate> 
<FooterTemplate>
</table>
</FooterTemplate> 
</asp:Repeater>

Open in new window

Comment
Watch Question

Meir RivkinFull stack Software Engineer
CERTIFIED EXPERT

Commented:
try using the <SessionParameter> tag instead of just the <Parameter> tag. That will let you set up automatic binding to the session variables.

Author

Commented:
Sedqwick -

I'm not using session variables, so I don't think I want to use <SessionParameter>, do I?

Again, I'm looping through the records in a repeater.  Within each record I want to query by the ID of the current record in the repeater, to have a nested gridview.  

The big thing .NET is not liking is the use of any sort of variable for the parameters DefaultValue.  I want to pass it <%# Eval("RecordID")%>, but it fails.
<asp:Parameter Name="fkID" Type="String" DefaultValue="<%# Eval("RecordID")%>" />

If I hard code a value, it works fine.  Like this:
<asp:Parameter Name="fkID" Type="String" DefaultValue="55411" />

Is there another way of setting that DefaultValue dynamically?  
Sr. Developer
CERTIFIED EXPERT
Commented:
This one is on us!
(Get your first solution completely free - no credit card required)
UNLOCK SOLUTION

Author

Commented:
I found a better solution for my problem a while, but I will try ADO.NET next time.  Thanks

Gain unlimited access to on-demand training courses with an Experts Exchange subscription.

Get Access
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Empower Your Career
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE

Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Unlock the solution to this question.
Join our community and discover your potential

Experts Exchange is the only place where you can interact directly with leading experts in the technology field. Become a member today and access the collective knowledge of thousands of technology experts.

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.