views:

48

answers:

1

Hi,

I have a gridview like this :

<asp:MultiView ID="MvCustomer" runat="server" ActiveViewIndex="0" >

<%--View 1 to List the customers--%>
<asp:View ID="VwCustomersList" runat="server" >
<asp:GridView ID="GvListCustomer" runat="server" AutoGenerateColumns="False" 
        HorizontalAlign="Center" DataSourceID="OdsGvCustomers" DataKeyNames="CUSNUM" 
        EnableModelValidation="True" onrowcommand="GvListCustomer_RowCommand"  >
    <Columns>
       <asp:TemplateField>
       <ItemTemplate>
       <asp:Label ID="LblCUSNUM" runat="server" Text='<%#Eval("CUSNUM") %>'></asp:Label>
       </ItemTemplate>
       </asp:TemplateField>
       <asp:TemplateField>
       <ItemTemplate>
       <asp:Label ID="LblCO_NAM" runat="server" Text='<%#Eval("CO_NAM") %>'></asp:Label>
       </ItemTemplate>
       </asp:TemplateField>
       <asp:TemplateField>
       <ItemTemplate>
       <asp:Label ID="LblCUSCTY" runat="server" Text='<%#Eval("CUSCTY") %>'></asp:Label>
       </ItemTemplate>
       </asp:TemplateField>
            <%--<asp:CommandField ButtonType="Button" SelectText="Edit" ShowSelectButton="true"  />--%>
            <asp:TemplateField>
            <ItemTemplate>
            <asp:Button ID="BtnSelect" runat="server" Text="Edit" CommandArgument='<%#Eval("CUSNUM")%>' CommandName="Select" />
            </ItemTemplate>
            </asp:TemplateField>
            <asp:TemplateField>
            <ItemTemplate>
            <asp:Button ID="BtnDelete" runat="server" Text="Delete" CommandArgument='<%#Eval("CUSNUM")%>' CommandName="Delete" />
            </ItemTemplate>
            </asp:TemplateField>

    </Columns>

</asp:GridView>

    <asp:ObjectDataSource ID="OdsGvCustomers" runat="server" 
        SelectMethod="GetAllCustomers" TypeName="MultiView_EF.BLL.Customers_BLL">
    </asp:ObjectDataSource>

</asp:View>

<%--View 2 to show customer details--%>
<asp:View ID="VwCustomerDetail" runat="server" >
<asp:FormView ID="FvCustomerDetails" runat="server" HorizontalAlign="Center" 
        DataSourceID="OdsFvCustomerDetails" EnableModelValidation="True" DefaultMode="Edit" >
    <EditItemTemplate>
        CUSNUM:
        <asp:TextBox ID="CUSNUMTextBox" runat="server" Text='<%# Bind("CUSNUM") %>' />
        <br />
        CO_NAM:
        <asp:TextBox ID="CO_NAMTextBox" runat="server" Text='<%# Bind("CO_NAM") %>' />
        <br />
        CUSCTY:
        <asp:TextBox ID="CUSCTYTextBox" runat="server" Text='<%# Bind("CUSCTY") %>' />
        <br />
        <asp:LinkButton ID="UpdateButton" runat="server" CausesValidation="True" 
            CommandName="Update" Text="Update" />
        &nbsp;<asp:LinkButton ID="UpdateCancelButton" runat="server" 
            CausesValidation="False" CommandName="Cancel" Text="Cancel" />
    </EditItemTemplate>
    <InsertItemTemplate>
        CUSNUM:
        <asp:TextBox ID="CUSNUMTextBox" runat="server" Text='<%# Bind("CUSNUM") %>' />
        <br />
        CO_NAM:
        <asp:TextBox ID="CO_NAMTextBox" runat="server" Text='<%# Bind("CO_NAM") %>' />
        <br />
        CUSCTY:
        <asp:TextBox ID="CUSCTYTextBox" runat="server" Text='<%# Bind("CUSCTY") %>' />
        <br />
        <asp:LinkButton ID="InsertButton" runat="server" CausesValidation="True" 
            CommandName="Insert" Text="Insert" />
        &nbsp;<asp:LinkButton ID="InsertCancelButton" runat="server" 
            CausesValidation="False" CommandName="Cancel" Text="Cancel" />
    </InsertItemTemplate>
    <%--<ItemTemplate>
        CUSNUM:
        <asp:Label ID="CUSNUMLabel" runat="server" Text='<%# Bind("CUSNUM") %>' />
        <br />
        CO_NAM:
        <asp:Label ID="CO_NAMLabel" runat="server" Text='<%# Bind("CO_NAM") %>' />
        <br />
        CUSCTY:
        <asp:Label ID="CUSCTYLabel" runat="server" Text='<%# Bind("CUSCTY") %>' />
        <br />
    </ItemTemplate>--%>
    </asp:FormView>

    <asp:ObjectDataSource ID="OdsFvCustomerDetails" runat="server" 
        SelectMethod="GetCustomerByCusnum" TypeName="MultiView_EF.BLL.Customers_BLL">
        <SelectParameters>
            <asp:ControlParameter ControlID="GvListCustomer" Name="cusnum" 
                PropertyName="SelectedValue" Type="String" />
        </SelectParameters>
    </asp:ObjectDataSource>

</asp:View>

</asp:MultiView>

My idea is that when the user clicks "BtnSelect" I will change the View to the view containing the FormView which has a select method configured to take the SelectedValue of the GridView as an input parameter - it will show the details of the selected customer.

I have done this before "n" number of times but I am not able to get it working this time. The trouble is that when the call for the Select Method of the formview goes to the relevant function - "GetCustomerByCusnum" I have a null value in its parameter "cusnum".

I know that I can write a selecting event and using CommandArgument, parse the value of the selected row and pass it into the Select method as a value but I dont want that solution. I know it works without the "Selecting" method but I cant recall how.

Please help.

A: 

By looking at your code, all seems ok, just a single hint, if you are not setting the active view, do it by SetActiveView method of multiview, please do that in button click.

Another thing you can do is: add OdsFvCustomerDetails_Selecting and OdsFvCustomerDetails_Selected events. in Selecting you can see the params and values passed and in Selected you can see e.Exception if there is any error in the query. so it will give you more idea about what exactly is going wrong.

Additional note
Another thing that should be noted is, multivew control works in a way that it binds all the views regardless of whichever is active so it degrades the performance. You may probably find better idea

lakhlaniprashant.blogspot.com
Hi,Yes on BtnSelect click, I am changing the view to the view containing the formview and then calling the DataBind()
Sandeep
Another thing you can do is: add OdsFvCustomerDetails_Selecting and OdsFvCustomerDetails_Selected events. in Selecting you can see the params and values passed and in Selected you can see e.Exception if there is any error in the query. so it will give you more idea about what exactly is going wrong.
lakhlaniprashant.blogspot.com
Yes, I know that can be done..but that is sort of an extra effort that is needed. I have done this before, and I didn't need to write the Selecting event. I think I am missing some setting or property...
Sandeep