James
James

Reputation: 216

Pull data from button in HTML to aspx page

Here's what I have so far:

Aspx file:

    <asp:DataList ID="DataList1" runat="server" DataKeyField="AppId" DataSourceID="TestDB" RepeatColumns="1">
        <ItemTemplate>
            AppId:
            <asp:Label ID="AppIdLabel" runat="server" Text='<%# Eval("AppId") %>' />
            <br />
            ToonName:
            <asp:Label ID="NameLabel" runat="server" Text='<%# Eval("Name") %>' />
            <br />
            AppStatus:
            <asp:Label ID="AppStatusLabel" runat="server" Text='<%# Eval("AppStatus") %>' />
            <br />
            <br />
        </ItemTemplate>
    </asp:DataList>
    <asp:SqlDataSource ID="TestDB" runat="server" ConnectionString="<%$ ConnectionStrings:ConnectionString %>" ProviderName="<%$ ConnectionStrings:ConnectionString.ProviderName %>" SelectCommand="SELECT * FROM [Applications] WHERE ([AppId] = @AppId)">
        <SelectParameters>
            <asp:QueryStringParameter Name="AppId" QueryStringField="btnView" Type="Int32" />
        </SelectParameters>
    </asp:SqlDataSource>

Grid that is auto populated using the database and creates a button for each action to be performed on that specific entry.

<form>
   <div id="grid">
       @grid.GetHtml(    
            tableStyle : "grid",
            alternatingRowStyle : "alt",
            headerStyle : "header",
            columns: grid.Columns(
                     grid.Column("AppId", "Action", format: @<text>
                            <button type="submit" class="view-app" id="@item.AppId" name="btnView" value="@item.AppId">View</button>
                            <button type="submit" class="approve-app" id="@item.AppId" name="btnApprove" value="@item.AppId">Approve</button>
                            <button type="submit" class="deny-app" id="@item.AppId" name="btnDeny" value="@item.AppId">Deny</button>
                            <button type="submit" class="delete-app" id="@item.AppId" name="btnDelete" value ="@item.AppId">Delete</button>
                        </text>),
                     grid.Column("Name", "Name"), 
                     grid.Column("AppDate", "AppDate"),
                     grid.Column("AppStatus", "Status")
        )
       )
    </div>
</form>
<br />
<fieldset>    
<legend>Applicant Answers</legend>
<iframe id="ff" width="100%" height="50px" frameborder="0" scroll="yes" src="Applicant.aspx"></iframe>
</fieldset>

What I am attempting to do is when a user clicks the button, I want the data to be populated in the aspx datalist. I know that the button does create the QueryString "btnView=". Plus the SQL Query does work, but no data is populated and no errors occur. Will this work, or will I need to approach this in a different manor?

UPDATED to reflect solution by Grundy

Edited as follows:

IFrame changed to:

<fieldset>  
<legend>Applicant Answers</legend>
    <script type="text/javascript">
        function ShowDetail(appId) {
            document.getElementById("ff").src ="Applicant.aspx?AppId=" + appId;};
    </script>
    <iframe id="ff" width="300" height="300"></iframe>
</fieldset>

Button changed to:

<button type="button" onclick="ShowDetail(this.value)" class="view-app" id="@item.AppId" name="btnView" value="@item.AppId">View</button>

Upvotes: 0

Views: 175

Answers (1)

Grundy
Grundy

Reputation: 13380

As i understand you don't need use submit, instead you need change src attribute for iframe. Change your code something like this

<script type="text/javascript">
    function ShowDetail(appId) {
        document.getElementById("ff").src = "Applicant.aspx?AppId=" + appId;
    }
</script>

....
<button type="button" onclick="ShowDetail(this.value)" class="view-app" id="@item.AppId" name="btnView" value="@item.AppId">View</button>
....

Upvotes: 1

Related Questions