views:

15

answers:

0

Hi, I have a datagridview which I assign an objectdatasource to bind data. My selectmethod has a parameter which is assigned at gridview_databinding. The code does not work as expected, using the debugger, it keeps firing the gridview_databinding event and entering the databind method in what seems like an infinite loop. Please help me figure out what I've done incorrectly by examining the code below.

The objectdatasource

<asp:ObjectDataSource DeleteMethod="Delete" SelectMethod="BindData"  ID="objDS"  runat="server"  TypeName="Discipline"> </asp:ObjectDataSource>

The datagridview

<asp:GridView ID="GridView1" runat="server" CellSpacing="2" BorderColor="green" BorderWidth="2px" DataSourceID="objDS" CellPadding="4" ForeColor="#333333" GridLines="None">
    <RowStyle BackColor="#EFF3FB" />
    <FooterStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
    <PagerStyle BackColor="#2461BF" ForeColor="White" HorizontalAlign="Center" />
    <SelectedRowStyle BackColor="#D1DDF1" Font-Bold="True" ForeColor="#333333" />
    <HeaderStyle BackColor="lightgreen" Font-Bold="True" ForeColor="Black" />
    <EditRowStyle BackColor="#2461BF" />
    <AlternatingRowStyle BackColor="White" />

    <Columns>       
        <asp:TemplateField Visible="false" HeaderText="RecID">
            <ItemTemplate>
                <asp:Label ID="lblRecID" runat="server" Text='<%# Bind("RecID") %>'></asp:Label>
            </ItemTemplate>
        </asp:TemplateField>       

        <asp:CommandField HeaderText="Delete" ShowDeleteButton="True" ButtonType="Link" />

        <asp:TemplateField HeaderText="Complete" ShowHeader="True">
            <ItemTemplate>
                <asp:LinkButton ID="btnComplete" runat="server" CausesValidation="false" Text="Complete" CommandArgument='<%# eval("RecID") %>' oncommand="btnComplete_Command" />
            </ItemTemplate>
        </asp:TemplateField>

    </Columns>

and then I wireup the event on the codebehind

   Protected Sub GridView1_DataBinding(ByVal sender As Object, ByVal e As System.EventArgs) Handles GridView1.DataBinding
        objDS.SelectParameters.Clear()
        objDS.SelectParameters.Add("Wl_Number", TypeCode.String, wl_value.ToString())
        objDS.Select()
    End Sub

and I have a class called discipline which has the BindData method

Public Function BindData(ByVal Wl_Number As String) As List(Of Discipline)
 'read data base
 'return List
End Function