Hello i have a dropdown list in edit mode and read only mode. If users upload pictures, i want them to chose a category for the uploaded pics and display it in a gridview as below.(See Picture below).
When i include "SelectedValue='<%# Bind("CategoryID")" in edit and item template mode, i get this error "'PictureReadOnlyCategories' has a SelectedValue which is invalid because it does not exist in the list of items.
Parameter name: value "
When i removed the "SelectedValue='<%# Bind("CategoryID")" from edit and item template, i get the result on the pic below(screenshot). If u can see the pic below the category is not selected, it just display the -- No Category -- even when i chose a category for the pic.
I want when a pic is uploaded and i category chosen, to display on the gridview. The code for the error message is below:
<EditItemTemplate>
<asp:DropDownList ID="pictureEditCategories" runat="server"
AppendDataBoundItems="True"
DataSourceID="categoriesDataSource"
DataTextField="Name" DataValueField="CategoryID"
SelectedValue='<%# Bind("CategoryID") %>' ValidationGroup="PictureEdit" >
<asp:ListItem Value="" Text="--No Category -- "/>
</asp:DropDownList>
</EditItemTemplate>
<ItemTemplate>
<asp:DropDownList ID="PictureReadOnlyCategories" runat="server"
AppendDataBoundItems="True" DataSourceID="categoriesDataSource"
DataTextField="Name" DataValueField="CategoryID" Enabled="False"
SelectedValue='<%# Bind("CategoryID") %>' ValidationGroup="PictureEdit"
>
<asp:ListItem Value="">-- No Category --</asp:ListItem>
</asp:DropDownList>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Title" SortExpression="Title">
<EditItemTemplate>
<asp:TextBox ID="TextBox1" runat="server" EnableViewState="False"
Text='<%# Bind("Title") %>'></asp:TextBox>
<asp:RequiredFieldValidator ID="RequiredFieldValidator4" runat="server"
ControlToValidate="TextBox1" Display="Dynamic"
ErrorMessage="must enter a title" ValidationGroup="PictureEdit"></asp:RequiredFieldValidator>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="Label1" runat="server" Text='<%# Bind("Title") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Description" SortExpression="Description">
<EditItemTemplate>
<asp:TextBox ID="TextBox2" runat="server" Columns="25" Rows="4"
Text='<%# Bind("Description") %>' TextMode="MultiLine"></asp:TextBox>
<asp:RequiredFieldValidator ID="RequiredFieldValidator5" runat="server"
ControlToValidate="TextBox2" Display="Dynamic"
ErrorMessage="you must enter a description" ValidationGroup="PictureEdit"></asp:RequiredFieldValidator>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="Label2" runat="server" Text='<%# Bind("Description") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Date Added" SortExpression="UploadedOn">
<EditItemTemplate>
<asp:Label ID="Label4" runat="server" Text='<%# Bind("UploadedOn") %>'></asp:Label>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="Label3" runat="server" Text='<%# Bind("UploadedOn") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:ImageField DataImageUrlField="PictureID"
DataImageUrlFormatString="~/UploadedImages/{0}.jpg" HeaderText="Image"
ReadOnly="True">
<ControlStyle Width="100px" />
</asp:ImageField>
</Columns>
<EditRowStyle BackColor="#2461BF" />
<FooterStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
<HeaderStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
<PagerStyle BackColor="#2461BF" ForeColor="White" HorizontalAlign="Center" />
<RowStyle BackColor="#EFF3FB" />
<SelectedRowStyle BackColor="#D1DDF1" Font-Bold="True" ForeColor="#333333" />
<SortedAscendingCellStyle BackColor="#F5F7FB" />
<SortedAscendingHeaderStyle BackColor="#6D95E1" />
<SortedDescendingCellStyle BackColor="#E9EBEF" />
<SortedDescendingHeaderStyle BackColor="#4870BE" />
</asp:GridView>
When i remove the SelectedValue='<%# Bind("CategoryID") %>' from the item and edit template, I get the result for the picture below.
Please i will appreciate your help.
Please you can edit the code or explain it to me since im still learning ASP.net
question answered
You have a DataSource defined with a parameterized query that contains two parameters:
#CategoryID
#UserID
However, you appear to only be populating one of the parameters via the Control Parameters.
Fixing this should be easy enough as you are already pulling the UserID from a query string variable in your other DataSource. You should be able to just copy the QueryStringParameter into your list of SelectParameters for your photo DataSource. Highlighted below:
You could also handle the Selecting event of the datasource and programatically set the UserID in the query that way, but the aforementioned option is easiest. I just want you to be aware of all your options.
Related
I have an existing SQL database and a ASP.NET application. My application has two existing GridViews and login functions. I also have an existing Crystal Report designed to automatically create a receipt from my SQL database. This is done by the user filling out 3 specific parameters, and the rest of the data (which are in parallel with those parameters) will automatically fill out the crystal report.
I want to create a print button in my GridView to automatically fill out the 3 parameters in the Crystal Report. This is an attempt to make my application more user friendly. In short, the user would push the print button in its new column in the GridView, and the 3 parameters would be automatically picked up and filled into the Crystal Report.
My parameters are: "EmpID", "KeyControl", and "ControlNumber". My crystal report label is "x.rpt"
Here is my GridView markup:
<asp:GridView ID="gridKeyAndBuildingInformation" runat="server" CssClass="style3"
AllowSorting ="True"
AutoGenerateColumns ="False"
AllowPaging="True"
DataKeyNames="KeyRefId"
OnRowCancelingEdit="gridKeyAndBuildingInformation_RowCancelingEdit"
onPageIndexChanging="gridKeyAndBuildingInformation_PageIndexChanging"
OnRowDataBound="gridKeyAndBuildingInformation_RowDataBound"
OnRowEditing="gridKeyAndBuildingInformation_RowEditing"
OnRowUpdating="gridKeyAndBuildingInformation_RowUpdating"
OnRowCommand="gridKeyAndBuildingInformation_RowCommand"
ShowFooter="True"
OnRowDeleting="gridKeyAndBuildingInformation_RowDeleting"
AlternatingRowStyle-BackColor="#EFEFEF"
EditRowStyle-VerticalAlign="Top"
HeaderStyle-BackColor="#77b218"
OnSorting="gridKeyAndBuildingInformation_Sorting"
BackColor="#CCCCCC"
BorderColor="#999999"
BorderStyle="Solid"
BorderWidth="3px"
CellPadding="4"
EnableModelValidation="True"
ForeColor="Black"
CellSpacing="2">
<Columns>
<asp:TemplateField HeaderText ="EmpID" HeaderStyle-CssClass="HeaderText" sortexpression="EmpID">
<ItemTemplate>
<asp:Label ID="lblEmpID" runat="server" Text='<%# Eval("EmpID") %>'></asp:Label>
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox ID="txtEmpID" runat="server" Text='<%# Eval("EmpID") %>' Width="50px"></asp:TextBox>
</EditItemTemplate>
<FooterTemplate>
<asp:TextBox ID="txtNewEmpID" runat="server" Width="50px"></asp:TextBox>
</FooterTemplate>
<HeaderStyle CssClass="HeaderText" />
</asp:TemplateField>
<asp:TemplateField HeaderText ="ControlNumber" HeaderStyle-CssClass="HeaderText" sortexpression="ControlNumber">
<ItemTemplate>
<asp:Label ID="lblControlNumber" runat="server" Text='<%# Eval("ControlNumber") %>'></asp:Label>
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox ID="txtControlNumber" runat="server" Text='<%# Eval("ControlNumber") %>' Width="50px"></asp:TextBox>
</EditItemTemplate>
<FooterTemplate>
<asp:TextBox ID="txtNewControlNumber" runat="server" Width="50px"></asp:TextBox>
</FooterTemplate>
<HeaderStyle CssClass="HeaderText" />
</asp:TemplateField>
<asp:TemplateField HeaderText ="KeyNumber" HeaderStyle-CssClass="HeaderText" sortexpression="KeyNumber">
<ItemTemplate>
<asp:Label ID="lblKeyNumber" runat="server" Text='<%# Eval("KeyNumber") %>'></asp:Label>
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox ID="txtKeyNumber" runat="server" Text='<%# Eval("KeyNumber") %>' Width="50px"></asp:TextBox>
</EditItemTemplate>
<FooterTemplate>
<asp:TextBox ID="txtNewKeyNumber" runat="server" Width="50px"></asp:TextBox>
</FooterTemplate>
<HeaderStyle CssClass="HeaderText" />
</asp:TemplateField>
<asp:TemplateField HeaderText="Edit" ShowHeader="False">
<EditItemTemplate>
<asp:LinkButton ID="LinkButton1" runat="server" CausesValidation="True" CommandName="Update" Text="Update"></asp:LinkButton>
<asp:LinkButton ID="LinkButton2" runat="server" CausesValidation="False" CommandName="Cancel" Text="Cancel"></asp:LinkButton>
</EditItemTemplate>
<FooterTemplate>
<asp:LinkButton ID="LinkButton2" runat="server" CausesValidation="False" CommandName="AddNew" Text="Add New"></asp:LinkButton>
</FooterTemplate>
<ItemTemplate>
<asp:LinkButton ID="LinkButton1" runat="server" CausesValidation="False" CommandName="Edit" Text="Edit"></asp:LinkButton>
</ItemTemplate>
</asp:TemplateField>
<asp:CommandField HeaderText="Delete" ShowDeleteButton="True" ShowHeader="True" />
<asp:ButtonField HeaderText="Print" ShowHeader="True" Text="Print" />
</Columns>
<EditRowStyle VerticalAlign="Top"></EditRowStyle>
<FooterStyle BackColor="#CCCCCC" />
<HeaderStyle BackColor="Black" Font-Bold="True" ForeColor="White"></HeaderStyle>
<PagerStyle BackColor="#CCCCCC" ForeColor="Black" HorizontalAlign="Left" />
<RowStyle BackColor="White" />
<SelectedRowStyle BackColor="#000099" Font-Bold="True" ForeColor="White" />
</asp:GridView>
You could handle the RowCommand event, which would fire when you click that delete button in your ButtonField column. Add this to the end of your GridView declaration markup (after "CellSpacing="2"" but before the ">"):
OnRowCommand="gridKeyAndBuildingInformation_RowCommand"
And then, in your code behind you would need something like this (this is C#, if you need VB.NET let me know - this question isn't tagged with a server-side language):
protected void gridKeyAndBuildingInformation_RowCommand(Object sender, GridViewCommandEventArgs e)
{
// Get your ID for the row you're on
int ID = Convert.ToInt32(e.CommandArgument);
// Get the row the button was clicked in
GridViewRow row = gridKeyAndBuildingInformation.Rows[ID];
// Get the values you need from that row
int EmpID = row.Cells[0];
int ControlNumber = row.Cells[1];
int KeyNumber = row.Cells[2];
// Use those numbers to make your call to the Crystal Report
// I don't know what this part would look like.
}
You can read more about the RowCommand event on MSDN: GridView.RowCommand Event
My GridView is DataBound to a SQL data connection which should almost always return data. So using an EmptyDataTemplate does not help me because the GridView should never be empty. But I want the first few rows to be editable so the user can add new information to the GridView. So I've crafted my Select statement to always come back with 3 empty rows. I want those rows to contain TextBoxes instead of Labels. But this:
<asp:GridView ID="GridView1" runat="server"
AutoGenerateColumns="False" DataSourceID="SqlDataSource1"
BorderColor="White" BorderStyle="Solid"
onselectedindexchanged="GridView1_SelectedIndexChanged" ShowFooter="False"
ViewStateMode="Disabled">
<Columns>
<asp:TemplateField>
<ItemTemplate>
<input type="checkbox" id ="CheckBox1" class="checkbox" />
</ItemTemplate>
<ItemStyle HorizontalAlign="Center" />
</asp:TemplateField>
<asp:TemplateField HeaderText="Serial" SortExpression="Serial">
<EditItemTemplate>
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="Label1" runat="server" Text='<%# Bind("Serial") %>'></asp:Label>
</ItemTemplate>
<ItemStyle HorizontalAlign="Center" />
</asp:TemplateField>
<asp:TemplateField HeaderText="Model" SortExpression="Model">
<EditItemTemplate>
<asp:TextBox ID="TextBox2" runat="server"></asp:TextBox>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="Label2" runat="server" Text='<%# Bind("Model") %>'></asp:Label>
</ItemTemplate>
<ItemStyle HorizontalAlign="Center" />
</asp:TemplateField>
<asp:TemplateField HeaderText="From Store">
<ItemTemplate>
<asp:DropDownList ID="DropDownList1" runat="server" CssClass="dropdownlist"
DataSourceID="SqlDataSource2" DataTextField="Store"
SelectedValue='<%# Bind("Store") %>'>
</asp:DropDownList>
</ItemTemplate>
<ItemStyle HorizontalAlign="Center" />
</asp:TemplateField>
<asp:TemplateField HeaderText="To Store">
<ItemTemplate>
<asp:DropDownList ID="DropDownList2" runat="server" CssClass="dropdownlist"
DataSourceID="SqlDataSource2" DataTextField="Store">
</asp:DropDownList>
</ItemTemplate>
<ItemStyle HorizontalAlign="Center" />
</asp:TemplateField>
</Columns>
<FooterStyle HorizontalAlign="Center" ForeColor="White" BorderColor="White" BorderStyle="Solid" />
<HeaderStyle ForeColor="White" BorderColor="White" BorderStyle="Solid" />
<RowStyle BorderColor="White" BorderStyle="Solid" ForeColor="White" />
</asp:GridView>
Produces this:
Where the first 3 rows have uneditable Labels rather than TextBoxes. Is what I want to do possible?
In your template fields add <FooterTemplate></FooterTemplate> This makes the footer row of your gridview a place where you can add new rows. Of course you will need to put items inside the <FooterTemplate>, but the work the same as your <ItemTemplates
So to serve my specific purpose, I decided just to create a table separate from this with an empty row with textboxes. Then a button that used JQuery to take the values from that table to append them into the uneditable row in the DataGrid. Removed the header row from the DataGrid so it all looked like the same table.
All respected, I have a Master detail project asp.net (sql data) project in which Master.aspx along with code behind page Master.aspx.cs. Following is the code:
<asp:TemplateField HeaderText="Date of Failure" SortExpression="Failure_date" >
<EditItemTemplate>
<asp:TextBox ID="EditFailure_date" runat="server" Text='<%# Bind("Failure_date", "{0:d}") %>' ></asp:TextBox><img src="_images/images.jpg" style="margin-top:3px;width:30px;height:30px;cursor:hand;" onclick="PopupPicker('EditFailure_date')" />
<asp:RequiredFieldValidator ID="Failure_dateRequiredFieldValidator" runat="server" ControlToValidate="EditFailure_date" Display="Dynamic" ErrorMessage="Can not be blank" SetFocusOnError="True"></asp:RequiredFieldValidator>
</EditItemTemplate>
<ItemStyle HorizontalAlign="Left" VerticalAlign="Top" />
<HeaderStyle HorizontalAlign="Left" VerticalAlign="Top" />
<ItemTemplate>
<asp:Label ID="Failure_date" runat="server" Text='<%# Bind("Failure_date", "{0:dd/MM/yyyy}") %>' ></asp:Label>
</ItemTemplate>
</asp:TemplateField>
Now I want to add a popup calender for above text box 'EditFailure_date' without codebehind. Please help.
You can use the AjaxControlToolkit's calendar like this:
<asp:TextBox ID="EditFailure_date" runat="server" Text='<%# Bind("Failure_date", "{0:d}") %>' ></asp:TextBox>
<ajaxToolkit:CalendarExtender runat="server" ID="cal_EditFailure_date" TargetControlID="EditFailure_date" />
Edit: You can also use a jquery solution such as the jQueryUI DatePicker
<asp:TextBox ID="txtDOJ" Text='<%# Bind("DOJ", "{0:dd-MMM-yyyy}") %>' runat="server" class="form-control input-sm m-bot15" BackColor="#cbeddc"></asp:TextBox> <asp:CalendarExtender ID="CalExtender" runat="server" Enabled="true" Format="dd-MMM-yyyy" TargetControlID="txtDOJ"> </asp:CalendarExtender>
I have fields for a contact. 3 of those fields are drop downs to values from another table in the database. For example, Contacts has the foreign key for departmentid which pulls from the department table to get the description. But when i click the Edit and update, this does not update my database. It acts like nothing happened.
EDIT: Just noticed this, but when i change the name and click update. I get an error telling me that EmployerCode cannot be set to null. I know that the database is set to not nullable. But i do not understand why the original value is not being pulled. When i load the contact, all three of the drop downs have values from the database loaded. Although i am seeing that all three are displaying the first item in the table and not the item the contact has in it's values. But when editing the contact, it acts like those values are not loaded and are just null.
<asp:DetailsView ID="detailsViewContact" runat="server" Height="90px" Width="293px"
DataSourceID="ContactDataSource" AutoGenerateRows="False"
BackColor="#FFCC66" BorderStyle="None" BorderWidth="0px" CellPadding="3"
DataKeyNames="ContactID" Font-Bold="True" HorizontalAlign="Center">
<CommandRowStyle BackColor="White" BorderColor="White" Font-Bold="True"
Font-Size="Large" HorizontalAlign="Center" />
<Fields>
<asp:BoundField DataField="SSOID" HeaderText="SSOID"
SortExpression="SSOID" />
<asp:BoundField DataField="FirstName" HeaderText="FirstName"
SortExpression="FirstName" />
<asp:BoundField DataField="Lastname" HeaderText="Lastname"
SortExpression="Lastname" />
<asp:BoundField DataField="Address" HeaderText="Address"
SortExpression="Address" />
<asp:BoundField DataField="City" HeaderText="City"
SortExpression="City" />
<asp:BoundField DataField="State" HeaderText="State"
SortExpression="State" />
<asp:BoundField DataField="ZipCode" HeaderText="ZipCode"
SortExpression="ZipCode" />
<asp:BoundField DataField="EmailAddress" HeaderText="EmailAddress"
SortExpression="EmailAddress" />
<asp:TemplateField HeaderText="AccessRightID" SortExpression="AccessRightID">
<EditItemTemplate>
<asp:DropDownList ID="DropDownList2" runat="server"
DataSourceID="AccessRightDataSource" DataTextField="AccessRightDescription"
DataValueField="AccessRightID">
</asp:DropDownList>
</EditItemTemplate>
<InsertItemTemplate>
<asp:DropDownList ID="DropDownList3" runat="server"
DataSourceID="AccessRightDataSource" DataTextField="AccessRightDescription"
DataValueField="AccessRightID">
</asp:DropDownList>
</InsertItemTemplate>
<ItemTemplate>
<asp:DropDownList ID="DropDownList10" Enabled="false" runat="server"
DataSourceID="AccessRightDataSource" DataTextField="AccessRightDescription"
DataValueField="AccessRightID">
</asp:DropDownList>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="EmployerCode" SortExpression="EmployerCode">
<EditItemTemplate>
<asp:DropDownList ID="DropDownList5" runat="server"
DataSourceID="EmployerDataSource" DataTextField="EmployerName"
DataValueField="EmployerCode">
</asp:DropDownList>
</EditItemTemplate>
<InsertItemTemplate>
<asp:DropDownList ID="DropDownList6" runat="server"
DataSourceID="EmployerDataSource" DataTextField="EmployerName"
DataValueField="EmployerCode">
</asp:DropDownList>
</InsertItemTemplate>
<ItemTemplate>
<asp:DropDownList ID="DropDownList4" Enabled="false" runat="server"
DataSourceID="EmployerDataSource" DataTextField="EmployerName"
DataValueField="EmployerCode">
</asp:DropDownList>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="DepartmentID" SortExpression="DepartmentID">
<EditItemTemplate>
<asp:DropDownList ID="DropDownList8" runat="server"
DataSourceID="DepartmentDataSource" DataTextField="Description"
DataValueField="DepartmentID">
</asp:DropDownList>
</EditItemTemplate>
<InsertItemTemplate>
<asp:DropDownList ID="DropDownList9" runat="server"
DataSourceID="DepartmentDataSource" DataTextField="Description"
DataValueField="DepartmentID">
</asp:DropDownList>
</InsertItemTemplate>
<ItemTemplate>
<asp:DropDownList ID="DropDownList7" Enabled="false" runat="server"
DataSourceID="DepartmentDataSource" DataTextField="Description"
DataValueField="DepartmentID">
</asp:DropDownList>
</ItemTemplate>
</asp:TemplateField>
<asp:CommandField ShowDeleteButton="True" ShowEditButton="True"
ShowInsertButton="True" />
</Fields>
here are my datasources
<asp:EntityDataSource ID="EmployerDataSource" runat="server"
ConnectionString="name=WorkStudyEntities"
DefaultContainerName="WorkStudyEntities" EnableFlattening="False"
EntitySetName="Employers" EnableUpdate="True">
It looks like this was a fluke somehow. I redid the page and it all worked correctly
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" />
<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" />
<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.
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
Yikes. A relic of a question - IIRC I did away with the MV approach for this as we moved list and details section to different aspx pages and used query string parameters. Never got to fix what must have been, in hindsight, some missing parameter assignment.