Link to home
Start Free TrialLog in
Avatar of JT_SIRO
JT_SIRO

asked on

Unable to pass datarepeater value into a sqldatasource parameter

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

Avatar of Meir Rivkin
Meir Rivkin
Flag of Israel image

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

ASKER

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?  
ASKER CERTIFIED SOLUTION
Avatar of Kelvin McDaniel
Kelvin McDaniel
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of JT_SIRO

ASKER

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