Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Embedded GridView

Status
Not open for further replies.

JimmyFo

Programmer
Feb 14, 2005
102
US
Hi, I have a working embedded gridview on one page that loads on the page load and pulls the select parameter from a query string; I tried to recreate it on another page where the grid is populated dynamically once a button is clicked, but it does not work:

Button click event:
[asp] grid_export.Visible = True
DSProject.SelectParameters("p_PORTFOLIOID").DefaultValue = e.CommandArgument
grid_export.DataBind()[/asp]

The Gridview with embedded Datasource and gridview:
Code:
        <asp:GridView ID="grid_export" Visible="false"
            DataSourceID="DSProject"
            AutoGenerateColumns="false"
            AutoGenerateEditButton="false"
            ShowHeader="false" runat="server" BackColor="White" BorderColor="#E7E7FF"
            BorderStyle="None" BorderWidth="1px" CellPadding="3" GridLines="Horizontal">
            <Columns>
                <asp:BoundField DataField="ProjectID" />
                <asp:TemplateField>
                    <ItemTemplate>
                        <!------------------------------------------------->
                        <!--DATASOURCE AND EMBEDDED GRID FOR MILESTONES-->
                        <!------------------------------------------------->
                        <asp:SqlDataSource ID="DSMilestone" runat="server"
                            ConnectionString="<%$ AppSettings:SQLConnection1 %>"
                            SelectCommand="uspSELECT_MILESTONE"
                            SelectCommandType="StoredProcedure">
                                <SelectParameters>
                                    <asp:Parameter Name="p_PROJECTID" />
                                </SelectParameters>
                            </asp:SqlDataSource>
                        <asp:GridView ID="grid_embedded"
                            Width="100%"
                            DataSourceID="DSMilestone"
                            DataKeyNames="intMilestoneID"
                            AutoGenerateColumns="true"
                            AutoGenerateEditButton="false"
                            AutoGenerateDeleteButton="false"
                            ShowHeader="false"
                            Visible="true"
                            CellPadding="4" ForeColor="#333333" runat="server">
                 </asp:GridView>
                    </ItemTemplate>
                </asp:TemplateField>
            </Columns>
        </asp:GridView>

Then there is the rowdatabound event where I try to assign the parameter to the embedded datasource:
Code:
    Protected Sub grid_export_RowDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles grid_export.RowDataBound
        If e.Row.RowType = DataControlRowType.DataRow And (e.Row.RowState = DataControlRowState.Normal Or e.Row.RowState = DataControlRowState.Alternate) Then
            'set milestone datasource parameter default value
            Dim tempds As SqlDataSource = CType(e.Row.FindControl("DSMilestone"), SqlDataSource)
            tempds.SelectParameters(0).DefaultValue = e.Row.DataItem("ProjectID")
            Dim temp As String
            temp = tempds.SelectParameters(0).ToString()
        End If
    End Sub

When I check "temp" while going through the debug process, I can see that the parameter's value is "p_PROJECTID" instead of the int that I am trying to assign it to. Any ideas?!

The visible is set to false as this grid is drawn solely to export to excel, but I've set it to true as well, and it doesn't work...

Thanks,
James
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top