In a Telerik RadGrid, the user has the ability to add a row and edit an existing one. It appears that the grids actually force a postback to occur before the UI controls are rendered on the screen. I'm noticing a second to two seconds delay from the time the button is clicked to the time the controls appear. This seems about a second to two seconds too long. Here is my code, I'm not exactly sure what the bug is.
I apologize in advance for the "whatz wrongz with me codez post", but this seems like the easiest way to go about this one. Again, I have a performance issue and would like to figure out how to solve it in terms of what code needs to be tweaked.....
<asp:UpdatePanel ID="upPhone" runat="server">
<contenttemplate>
<telerik:RadGrid runat="server" ID="gridPhone" DataSourceID="dsPhone" AutoGenerateColumns="False"
Width="100%" AllowAutomaticDeletes="True" AllowAutomaticInserts="True"
GridLines="None" Skin="Vista" AllowAutomaticUpdates="True"
ondatabound="gridPhone_DataBound" onitemdeleted="gridPhone_ItemDeleted"
oniteminserted="gridPhone_ItemInserted"
onitemupdated="gridPhone_ItemUpdated"
onneeddatasource="gridPhone_NeedDataSource">
<MasterTableView DataKeyNames="phone_id" CommandItemDisplay="Top"
EditMode="InPlace" AllowFilteringByColumn="False">
<Columns>
<telerik:GridEditCommandColumn ButtonType="ImageButton" UniqueName="EditCommandColumn">
<ItemStyle CssClass="MyImageButton" />
</telerik:GridEditCommandColumn>
<telerik:GridBoundColumn DataField="phone_id" ReadOnly="true" UniqueName="phone_id"
Visible="false">
</telerik:GridBoundColumn>
<telerik:GridDropDownColumn DataField="d_phone_type_id" DataSourceID="dsPhoneType"
UniqueName="d_phone_type_id" DataType="System.Int32" ListValueField="d_phone_type_id"
ListTextField="name" HeaderText="Type">
</telerik:GridDropDownColumn>
<telerik:GridTemplateColumn HeaderText="Number" SortExpression="number" UniqueName="number">
<ItemTemplate>
<asp:Label runat="server" ID="lblPhoneNumber" Text='<%# Eval("number", "{0:(###) ###-####}") %>'></asp:Label>
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox ID="txtNumber" MaxLength="10" runat="server" Text='<%# Bind("number") %>'></asp:TextBox>
</EditItemTemplate>
</telerik:GridTemplateColumn>
<telerik:GridBoundColumn DataField="description" UniqueName="description" HeaderText="Description">
</telerik:GridBoundColumn>
<telerik:GridCheckBoxColumn DataField="isprimary" UniqueName="isprimary" HeaderText="Primary"
DataType="System.Int16">
</telerik:GridCheckBoxColumn>
<telerik:GridButtonColumn ConfirmText="Delete this number?" ConfirmDialogType="RadWindow"
ConfirmTitle="Delete" ButtonType="ImageButton" CommandName="Delete" Text="Delete"
UniqueName="DeleteColumn">
<ItemStyle HorizontalAlign="Center" CssClass="MyImageButton" />
</telerik:GridButtonColumn>
</Columns>
<EditFormSettings>
<EditColumn UniqueName="EditCommandColumn1">
</EditColumn>
</EditFormSettings>
</MasterTableView>
<ClientSettings>
<Selecting AllowRowSelect="True" />
</ClientSettings>
</telerik:RadGrid>
<asp:ObjectDataSource ID="dsPhoneType" runat="server"
OldValuesParameterFormatString="original_{0}" SelectMethod="GetPhoneTypes"
TypeName="DataAccess"></asp:ObjectDataSource>
<asp:SqlDataSource ID="dsPhone" runat="server" ConnectionString="<%$ ConnectionStrings:TBD %>"
DeleteCommand="DELETE FROM [phone] WHERE [phone_id] = #phone_id" InsertCommand="INSERT INTO [phone] ([person_id],[d_phone_type_id], [number], [description], [isprimary]) VALUES (#person_id,#d_phone_type_id, #number, #description, #isprimary)"
SelectCommand="get_PhoneById" UpdateCommand="UPDATE [phone] SET [d_phone_type_id] = #d_phone_type_id, [number] = #number, [description] = #description, [isprimary] = #isprimary WHERE [phone_id] = #phone_id"
SelectCommandType="StoredProcedure">
<SelectParameters>
<asp:ControlParameter ControlID="lblID" Name="person_id" PropertyName="Text" Type="Int32" />
</SelectParameters>
<DeleteParameters>
<asp:Parameter Name="phone_id" Type="Int32" />
</DeleteParameters>
<UpdateParameters>
<asp:Parameter Name="d_phone_type_id" Type="Int32" />
<asp:Parameter Name="number" Type="Int64" />
<asp:Parameter Name="description" Type="String" />
<asp:Parameter Name="isprimary" Type="Boolean" />
<asp:Parameter Name="phone_id" Type="Int32" />
</UpdateParameters>
<InsertParameters>
<asp:ControlParameter ControlID="lblID" Name="person_id" PropertyName="Text" />
<asp:Parameter Name="d_phone_type_id" Type="Int32" />
<asp:Parameter Name="number" Type="Int64" />
<asp:Parameter Name="description" Type="String" />
<asp:Parameter Name="isprimary" Type="Boolean" />
</InsertParameters>
</asp:SqlDataSource>
</contenttemplate>
</asp:UpdatePanel>
Just a couple of things to check:
Are you duplicating the bind behaviour in the gridPhone_NeedDataSource event, your ItemUpdated, Deleted and Inserted events, and the native Rad Grid binding behviour (by using a asp:SqlDataSource control)? It would be useful to see your code-behind to see if you are or not.
How many records do you have in the grid? I find if I have a large number of items in the Grid and have some of the advanced features turned on (I've noticed you've got row selecting enabled) the grid grinds to a halt.
If none of these work/apply to your situation then it maybe worth checking the performance section of their site.
I am seeing that you are using DataSourceID="dsPhone" and onneeddatasource="gridPhone_NeedDataSource"
not sure if you need both. Also make sure you dont do a DataBind() else where in your code (page_Load or any other place) since you already have OnNeedDataSource event attached to the grid
Related
(I found the way it's supposed to be done as shown in my Answer below.
I'm editing my question and deleting the code I initially put here, which was a mess, leaving just the definitions).
Win7, ASP4.5, empty_web_app in VS2013 with C#. Recreated in a very simple project accessing two tables:
1st table "Students"
student_ID
student_name
student_course_ID (is Forign Key)
2nd table "Courses"
course_ID
course_name
In my web page I have DetailView1 showing details of student who's student_ID is taken from txbStudent_ID.
DetailView1 has Edit Delete and New.
When in UPDATE or INSERT mode I need to show the course_name (rather then the course ID) in a drop-down-list and update/insert accordingly.
No code behind.
My answer below is applicable to GRIDVIEW as well.
Gadi
I was so wrong they way I coded my aspx.
So here is the right way to do it, for future beginners like I am now...
(with the help of https://msdn.microsoft.com/en-us/library/ms178294(v=vs.140).aspx)
<asp:Label ID="Label1" runat="server" Text="Student_ID"></asp:Label>
<asp:TextBox ID="txbStudent_ID" runat="server"></asp:TextBox>
<br />
<asp:DetailsView ID="DetailsView1" runat="server" AutoGenerateRows="False" DataKeyNames="student_ID" DataSourceID="SqlDataSource1" Height="50px" Width="125px">
<Fields>
<asp:BoundField DataField="student_ID" HeaderText="student_ID" InsertVisible="False" ReadOnly="True" SortExpression="student_ID" />
<asp:BoundField DataField="student_name" HeaderText="student_name" SortExpression="student_name" />
<asp:TemplateField HeaderText="student_course_ID" SortExpression="student_course_ID">
<EditItemTemplate>
<asp:DropDownList
ID="DropDownList1"
runat="server"
DataSourceID="SqlDataSource2"
DataTextField="course_name"
DataValueField="course_ID"
SelectedValue='<%# Bind("student_course_ID") %>'>
</asp:DropDownList>
</EditItemTemplate>
<InsertItemTemplate>
<asp:DropDownList
ID="DropDownList2"
runat="server"
DataSourceID="SqlDataSource2"
DataTextField="course_name"
DataValueField="course_ID"
SelectedValue='<%# Bind("student_course_ID") %>'>
</asp:DropDownList>
</InsertItemTemplate>
<ItemTemplate>
<asp:Label
ID="Label1"
runat="server"
Text='<%# Bind("student_course_ID") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:CommandField ShowEditButton="True" ShowInsertButton="True" ShowDeleteButton="True" />
</Fields>
</asp:DetailsView>
<asp:SqlDataSource
ID="SqlDataSource1"
runat="server"
ConnectionString="<%$ ConnectionStrings:Course_Student_Connection %>"
InsertCommand="INSERT INTO [Students] ([student_name], [student_course_ID]) VALUES (#student_name, #student_course_ID)"
SelectCommand="SELECT * FROM [Students] WHERE ([student_ID] = #student_ID)"
UpdateCommand="UPDATE [Students] SET [student_name] = #student_name, [student_course_ID] = #student_course_ID WHERE [student_ID] = #student_ID"
DeleteCommand="DELETE FROM [Students] WHERE [student_ID] = #student_ID">
<DeleteParameters>
<asp:Parameter Name="student_ID" Type="Int32" />
</DeleteParameters>
<InsertParameters>
<asp:Parameter Name="student_name" Type="String" />
<asp:Parameter Name="student_course_ID" Type="Int32" />
</InsertParameters>
<SelectParameters>
<asp:ControlParameter ControlID="txbStudent_ID" Name="student_ID" PropertyName="Text" Type="Int32" />
</SelectParameters>
<UpdateParameters>
<asp:Parameter Name="student_name" Type="String" />
<asp:Parameter Name="student_course_ID" Type="Int32" />
<asp:Parameter Name="student_ID" Type="Int32" />
</UpdateParameters>
</asp:SqlDataSource>
<asp:SqlDataSource
ID="SqlDataSource2"
runat="server"
ConnectionString="<%$ ConnectionStrings:Course_Student_Connection %>"
SelectCommand="SELECT [course_ID], [course_name] FROM [Courses]">
</asp:SqlDataSource>
I do hope it will save some time for others.
Stackoverflow is THE greatest and by far the best Q&A site on the web!!!
Gadi.
I have a problem with ASPxGridView.
I have a aspxgridview1 contain button.
aspxgridview2 contain data.
when I pressed the button. data will be displayed on the aspgridview2 corresponding "ID" of aspxgridview1 but without reloading the page.
this is following aspxgridview1
<dx:ASPxGridView ID="ASPxGridView1" runat="server" AutoGenerateColumns="False" DataSourceID="SqlDataSource1" KeyFieldName="Province_Id">
<Columns>
<dx:GridViewCommandColumn VisibleIndex="0">
<EditButton Visible="True">
</EditButton>
<ClearFilterButton Visible="True">
</ClearFilterButton>
<CustomButtons>
<dx:GridViewCommandColumnCustomButton ID="show" Text="show">
</dx:GridViewCommandColumnCustomButton>
</CustomButtons>
</dx:GridViewCommandColumn>
<dx:GridViewDataTextColumn FieldName="Province_Id" ReadOnly="True" VisibleIndex="1">
<EditFormSettings Visible="False" />
</dx:GridViewDataTextColumn>
<dx:GridViewDataTextColumn FieldName="Name" VisibleIndex="2">
</dx:GridViewDataTextColumn>
<dx:GridViewDataButtonEditColumn VisibleIndex="4">
</dx:GridViewDataButtonEditColumn>
</Columns>
<SettingsBehavior AllowFocusedRow="True" />
<Settings ShowFilterRow="True" ShowFooter="True" ShowGroupPanel="True" ShowTitlePanel="True" />
</dx:ASPxGridView>
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:TravelConnectionString %>" DeleteCommand="DELETE FROM [Province] WHERE [Province_Id] = #Province_Id" InsertCommand="INSERT INTO [Province] ([Name]) VALUES (#Name)" SelectCommand="SELECT * FROM [Province]" UpdateCommand="UPDATE [Province] SET [Name] = #Name WHERE [Province_Id] = #Province_Id">
<DeleteParameters>
<asp:Parameter Name="Province_Id" Type="Int32" />
</DeleteParameters>
<InsertParameters>
<asp:Parameter Name="Name" Type="String" />
</InsertParameters>
<UpdateParameters>
<asp:Parameter Name="Name" Type="String" />
<asp:Parameter Name="Province_Id" Type="Int32" />
</UpdateParameters>
</asp:SqlDataSource>
If you're set on using the ASPxGridViews, the best you can do is wrap both controls in UpdatePanels. If you don't like that solution, you'll need to look into using ajax to get the data after clicking a button.
Solution at the bottom.
I receive the following error when trying to update records:
Must declare Scalar Variable #PaymentTermID
Problem is, #PaymentTermID should be defined already in the Update parameters. The 2 functions for onrowdatabound and onrowupdate are tweaked versions of the ones found here for the DropDownList: GridViewRow.DataItem Property. Delete works fine.
No new lines are added, just names changed around. Any help would be appreciated, I am not exactly used to working with asp objects.
<asp:GridView ID="GridView1" onrowdatabound="GridView1_RowDataBound" onrowupdating="GridView1_RowUpdating" runat="server" AutoGenerateColumns="False" DataKeyNames="PaymentTermID" DataSourceID="SqlDataSource1" CellPadding="1" CellSpacing="2">
<Columns>
<asp:CommandField ShowEditButton="True" />
<asp:TemplateField HeaderText="Key Contract Date" SortExpression="Key Contract Date">
<EditItemTemplate>
<asp:DropDownList ID="DropDownList1" runat="server" DataSourceID="SqlDataSource2" DataTextField="Key_Contract_Date" DataValueField="Key_Contract_Date" />
<asp:SqlDataSource ID="SqlDataSource2" runat="server" ConnectionString="<%$ ConnectionStrings:Production_DatabaseConnectionString %>"
SelectCommand="SELECT DISTINCT [Key Contract Date] AS Key_Contract_Date FROM [tblPRJ_PaymentTerms]" />
</EditItemTemplate>
<ItemTemplate>
<asp:TextBox ID="TextBox1" runat="server" Text='<%# Bind("[Key Contract Date]") %>' />
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="Due Date" HeaderText="Due Date" SortExpression="Due Date" />
<asp:BoundField DataField="Percent Due" HeaderText="Percent Due" SortExpression="Percent Due" />
<asp:BoundField DataField="Custom Description" HeaderText="Custom Description" SortExpression="Custom Description" />
</Columns>
<HeaderStyle Font-Bold="True" ForeColor="#666666" />
</asp:GridView>
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:Production_DatabaseConnectionString %>"
SelectCommand="SELECT * FROM [tblPRJ_PaymentTerms] WHERE ([Job Number] = #Job_Number)"
DeleteCommand="DELETE FROM [tblPRJ_PaymentTerms] WHERE [PaymentTermID] = #PaymentTermID"
InsertCommand="INSERT INTO [tblPRJ_PaymentTerms] ([Job Number], [Key Contract Date], [Due Date], [Percent Due], [Custom Description]) VALUES (#Job_Number, #Key_Contract_Date, #Due_Date, #Percent_Due, #Custom_Description)"
UpdateCommand="UPDATE [tblPRJ_PaymentTerms] SET [Job Number] = #Job_Number, [Key Contract Date] = #Key_Contract_Date, [Due Date] = #Due_Date, [Percent Due] = #Percent_Due, [Custom Description] = #Custom_Description WHERE [PaymentTermID] = #PaymentTermID">
<DeleteParameters>
<asp:Parameter Name="PaymentTermID" Type="Int32" />
</DeleteParameters>
<InsertParameters>
<asp:Parameter Name="Job_Number" Type="String" />
<asp:Parameter Name="Key_Contract_Date" Type="String" />
<asp:Parameter Name="Due_Date" Type="DateTime" />
<asp:Parameter Name="Percent_Due" Type="Decimal" />
<asp:Parameter Name="Custom_Description" Type="String" />
</InsertParameters>
<SelectParameters>
<asp:ControlParameter ControlID="txtCurrentJobNumber" Name="Job_Number" PropertyName="Text" Type="String" />
</SelectParameters>
<UpdateParameters>
<asp:Parameter Name="Job_Number" Type="String" />
<asp:Parameter Name="Key_Contract_Date" Type="String" />
<asp:Parameter Name="Due_Date" Type="DateTime" />
<asp:Parameter Name="Percent_Due" Type="Decimal" />
<asp:Parameter Name="Custom_Description" Type="String" />
<asp:Parameter Name="PaymentTermID" Type="Int32" />
</UpdateParameters>
</asp:SqlDataSource>
SOLUTION: There were multiple problems happening here. First and foremost, GuthMD was correct in his assessment of parameters needing a reference in terms of either a boundfield, templatefield, or other source (such as a control in the case of a control parameter). Simply creating an asp:boundfield for the PaymentTermID and setting the Visible property to false fixed the problem I posted about.
The other problem was that the database was setup poorly, and had spaces in column names. The OLEDB driver doesn't like that, and causes errors when you try to write back to the database and you have spaces in column names (even if it's encased in brackets []). After fixing the names in SQL, then revisiting our code and rewriting most of the SQL code for it, things started behaving as expected.
Thanks again for your help.
I've been looking through the MSDN documentation for Using Parameters, and it seems that for the binding to be created between the GridView and your SqlDataSource that your GridView is going to need to have BoundField elements corresponding to the Parameter elements.
Add the following to the <Columns> of your GridView:
<asp:BoundField DataField="Job_Number" Visible="false" />
<asp:BoundField DataField="Key_Contract_Date" Visible="false" />
<asp:BoundField DataField="Due_Date" Visible="false" />
<asp:BoundField DataField="Percent_Due" Visible="false" />
<asp:BoundField DataField="Custom_Description" Visible="false" />
<asp:BoundField DataField="PaymentTermID" Visible="false" />
1-The problem occurs when datasource is OleDb not SQLclient.
Change the DataSource1 to :
providerName="System.Data.SqlClient"
2-Make sure valid binding field in grid definition DataKeyNames="id_field"
I'm binding a GridView to a ObjectDataSource.
I'm expecting the m_ObjectDataSourceGrid_Selected method to fire twice, once for the Select and again for the Count, but it only fires once.
What's going on?
<asp:GridView ID="m_GridViewDocClasses" runat="server" AutoGenerateColumns="False"
DataSourceID="m_ObjectDataSourceGrid"
AllowSorting="true">
<Columns>
<asp:HyperLinkField DataNavigateUrlFields="Id" DataNavigateUrlFormatString="DocClass.aspx?DocClassId={0}"
Text="Edit" />
<asp:BoundField DataField="Name" HeaderText="Name" SortExpression="Name" />
<asp:BoundField DataField="Description" HeaderText="Description" SortExpression="Description" />
</Columns>
</asp:GridView>
</div>
<asp:ObjectDataSource ID="m_ObjectDataSourceGrid" runat="server" SelectMethod="GetDocClasses"
TypeName="SouthernCompany.Generation.SPORT.Business.DocClassBL" OnObjectCreating="m_ObjectDataSourceGrid_ObjectCreating"
OnSelected="m_ObjectDataSourceGrid_Selected" SelectCountMethod="GetDocClassesCount"
SortParameterName="sort">
<SelectParameters>
<asp:Parameter DefaultValue="" Name="sort" Type="String" />
<asp:Parameter DefaultValue="0" Name="startRowIndex" Type="Int32" />
<asp:Parameter DefaultValue="0" Name="maximumRows" Type="Int32" />
<asp:Parameter DefaultValue="0" Name="docClassId" Type="Int32" />
</SelectParameters>
</asp:ObjectDataSource>
You can not because you haven't assigned allowpaging, put these three:
AllowPaging="true"
AllowSorting="true"
PageSize="25"
AllowPaging is needed to call the SelectCountMethod.
remove allowsorting if not needed.
Does your SelectCountMethod is receiving the same parameters as SelectMethod? There's two ways that makes SelectCountMethod acceptable: without any parameter "()" or with the same parameters as SelectMethod, besides Sorting and Paging parameters.
I have a gridview that, when in edit mode, I use a dropdown to load all provinces, however, when I change the province and click update, my page crashes...I'm not sending the province parameter to the gridview's updateparameters properly...here's my code, someone please help..
<asp:GridView runat="server" ID="gvUsers" DataKeyNames="UserID" BackColor="#eeeeee" Width="85%"
HorizontalAlign="Center"
Font-Bold="False" Font-Names="Verdana"
Font-Size="10pt" AutoGenerateColumns="False"
OnRowDataBound="gvUsers_RowDataBound"
OnRowDeleting="gvUsers_RowDeleting" >
<HeaderStyle BackColor="#904601" ForeColor="White"
Font-Bold="True" HorizontalAlign="Left" />
<SelectedRowStyle BackColor="Yellow" />
<AlternatingRowStyle BackColor="White" Font-Bold="false" />
<Columns>
<asp:TemplateField>
<ItemTemplate>
<asp:LinkButton ID="LinkButton2"
CommandArgument='<%# Eval("UserID") %>'
CommandName="Select" runat="server">
Select</asp:LinkButton>
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="UserID" Visible="False" />
<asp:TemplateField HeaderText="Name">
<ItemTemplate>
<asp:Label ID="Label1" runat="server" Text='<%# Bind("FirstName") %>'></asp:Label>
<asp:Label ID="Label2" runat="server" Text='<%# Eval("LastName") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Delete?">
<ItemTemplate>
<asp:LinkButton ID="LinkButton1"
CommandArgument='<%# Eval("UserID") %>'
CommandName="Delete" runat="server">
Delete</asp:LinkButton>
</ItemTemplate>
</asp:TemplateField>
</Columns>
<RowStyle HorizontalAlign="Left" />
</asp:GridView><br /><br />
<asp:DetailsView runat="server" ID="dvUser" DataSourceID="SqlDataSource1" AutoGenerateRows="False" Width="85%" DataKeyNames="UserID"
HorizontalAlign="Center" AutoGenerateInsertButton="True" AutoGenerateEditButton="True" OnItemInserted="dvUsers_ItemInserted" >
<Fields>
<asp:BoundField DataField="UserID" Visible="False" />
<asp:BoundField DataField="FirstName" HeaderText="FirstName" SortExpression="FirstName" />
<asp:BoundField DataField="LastName" HeaderText="LastName" SortExpression="LastName" />
<asp:BoundField DataField="UserName" HeaderText="UserName" ReadOnly="true" SortExpression="UserName" />
<asp:TemplateField HeaderText="Password">
<ItemTemplate>
<asp:Label runat="server" ID="lblPassword" Text="●●●●●●●●●"></asp:Label>
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox runat="server" ID="txtPassword" TextMode="Password" Text='<%# Bind("Password") %>'>
</asp:TextBox>
</EditItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Birthdate" SortExpression="Birthdate">
<EditItemTemplate>
<asp:TextBox runat="server" ID="Birthdate" Text='<%# Bind("Birthdate") %>' ></asp:TextBox>
</EditItemTemplate>
<ItemTemplate>
<asp:Label runat="Server" ID="lblBirthdate" Text='<%# Bind("Birthdate") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="Address" HeaderText="Address" SortExpression="Address" />
<asp:BoundField DataField="Apt" HeaderText="Apt" SortExpression="Apt" />
<asp:BoundField DataField="City" HeaderText="City" SortExpression="City" />
<asp:TemplateField HeaderText="Province">
<ItemTemplate>
<asp:Label runat="server" ID="lblProvince" Text='<%# Eval("ProvName") %>'></asp:Label>
</ItemTemplate>
<EditItemTemplate>
<asp:DropDownList runat="server" ID="ddlProvince" DataValueField="ProvinceID" DataSourceID="SqlDataSource2" DataTextField="Province"></asp:DropDownList>
</EditItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="PostalCode" HeaderText="PostalCode" SortExpression="PostalCode" />
<asp:BoundField DataField="PhoneNum" HeaderText="PhoneNum" SortExpression="PhoneNum" />
<asp:BoundField DataField="Email" HeaderText="Email" SortExpression="Email" />
<asp:CheckBoxField DataField="ynAdminUser" HeaderText="ynAdminUser" SortExpression="ynAdminUser" />
</Fields>
</asp:DetailsView>
<asp:SqlDataSource ID="SqlDataSource2"
runat="server" ConnectionString="<%$ ConnectionStrings:ConnectionString %>"
SelectCommand="SELECT ProvinceID, Province FROM tblProvince"></asp:SqlDataSource>
<asp:SqlDataSource ID="SqlDataSource1"
runat="server" ConnectionString="<%$ ConnectionStrings:ConnectionString %>"
SelectCommand="SELECT a.UserID, a.FirstName, a.LastName, a.UserName, a.Password, a.Birthdate, a.Address, a.Apt, a.City, a.Province, b.Province as 'ProvName',
a.PostalCode, a.PhoneNum, a.Email, a.ynAdminUser
FROM tblUser a
INNER JOIN tblProvince B ON A.Province = B.ProvinceID
WHERE (a.UserID = #UserID) AND (a.ynDelete = 0)"
InsertCommand="INSERT INTO tblUser(FirstName, LastName, UserName, Password, Birthdate, Address, Apt, City, Province, PostalCode, Email, PhoneNum, ynAdminUser, ynDelete) VALUES (#FirstName, #LastName, #UserName, #Password, #Birthdate, #Address, #Apt, #City, #Province, #PostalCode, #Email, #PhoneNum, #ynAdminUser, 0)"
UpdateCommand="UPDATE tblUser SET FirstName = #FirstName, LastName = #LastName, Birthdate = #Birthdate, Address = #Address, Apt = #Apt, City = #City, Province = #Province, PostalCode = #PostalCode, PhoneNum = #PhoneNum, Email = #Email, ynAdminUser = #ynAdminUser WHERE (UserID = #UserID)">
<SelectParameters>
<asp:ControlParameter ControlID="gvUsers" Name="UserID" PropertyName="SelectedValue" Type="Int32" />
</SelectParameters>
<UpdateParameters>
<asp:Parameter Name="FirstName" Type="String" />
<asp:Parameter Name="LastName" Type="String" />
<asp:Parameter DbType="DateTime" Name="BirthDate" />
<asp:Parameter Name="Address" Type="String" />
<asp:Parameter Name="Apt" Type="String" />
<asp:Parameter Name="City" Type="String" />
<asp:ControlParameter Name="Province" ControlID="ddlProvince" PropertyName="SelectedValue" Type="Int32" />
<asp:Parameter Name="PhoneNum" Type="String" />
<asp:Parameter Name="Email" Type="String" />
<asp:Parameter Name="ynAdminUser" Type="Boolean" />
<asp:Parameter Name="UserID" Type="Int32" />
</UpdateParameters>
<InsertParameters>
<asp:Parameter Name="FirstName" Type="String" />
<asp:Parameter Name="LastName" Type="String" />
<asp:Parameter Name="UserName" Type="String" />
<asp:Parameter Name="Password" Type="String" />
<asp:Parameter DbType="DateTime" Name="Birthdate" />
<asp:Parameter Name="Address" Type="String" />
<asp:Parameter Name="Apt" Type="String" />
<asp:Parameter Name="City" Type="String" />
<asp:Parameter Name="Province" Type="Int32" />
<asp:Parameter Name="PostalCode" Type="String" />
<asp:Parameter Name="Email" Type="String" />
<asp:Parameter Name="PhoneNum" Type="String" />
<asp:Parameter Name="ynAdminUser" Type="Boolean" />
</InsertParameters>
</asp:SqlDataSource>
You don't need the control binding:
<asp:ControlParameter Name="Province" ControlID="ddlProvince" PropertyName="SelectedValue" Type="Int32" />
Instead, use a regualar parameter like your others and add the following binding to your drop-down list for the edit mode of the gridview:
SelectedValue=<%#Bind("Province")%>
I realize this is a really old question, and I hope you found your answer.
Looking at your markup, though, I want to say your connection strings were never filled out:
runat="server" ConnectionString="<%$ ConnectionStrings:ConnectionString %>"
I am not the strongest when it comes to ASP.NET databinding in the markup code, but I am pretty sure your connection string needs to point to an actual string name in your web.Config file's ConnectionStrings section:
<connectionStrings>
<clear />
<add name="Mark1" connectionString="Data Source=localhost;Initial Catalog=Table1;Integrated Security=True;" providerName="System.Data.SqlClient" />
</connectionStrings>
Use whatever your actual connection string is, though.
Now, your markup should be written as:
runat="server" ConnectionString="<%$ ConnectionStrings:Mark1 %>"
Again, I'm new to this. I found this only while trying to search for ways to solve my own problems.
If this is wrong (possible), someone just let me know what I did wrong and I'll delete it.