detailed information for each entry in gridview - asp.net

So i have made a Web Form with a dropdownlist which contains different classes in school and if you select one you get all the students of the selected class in the GridView below. So what i want to make now is, that if i click on a student it should open a more detailed page about the student, but i have no clues how to do this. I get all my data of a .mdf database file.
<%# Page Title="" Language="C#" MasterPageFile="~/Site.Master" AutoEventWireup="true" CodeBehind="schueler.aspx.cs" Inherits="ASPXUebung.schueler" %>
<asp:DropDownList ID="selectklassen" runat="server" DataSourceID="SqlDataSource1klassenselect" DataTextField="K_Bez" DataValueField="K_ID" AutoPostBack="true"></asp:DropDownList>
<asp:SqlDataSource ID="SqlDataSource1klassenselect" runat="server" ConnectionString="<%$ ConnectionStrings:ConnectionString %>" SelectCommand="SELECT [K_Bez], [K_ID] FROM [klassen] ORDER BY [K_Bez]"></asp:SqlDataSource>
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" DataKeyNames="S_SCHNR" DataSourceID="SqlDataSource1schueler">
<Columns>
<asp:BoundField DataField="S_SCHNR" HeaderText="S_SCHNR" ReadOnly="True" SortExpression="S_SCHNR" />
<asp:BoundField DataField="S_Name" HeaderText="S_Name" SortExpression="S_Name" />
<asp:BoundField DataField="S_Vorname" HeaderText="S_Vorname" SortExpression="S_Vorname" />
<asp:BoundField DataField="S_Gebdat" HeaderText="S_Gebdat" SortExpression="S_Gebdat" />
<asp:BoundField DataField="S_Adresse" HeaderText="S_Adresse" SortExpression="S_Adresse" />
<asp:BoundField DataField="S_K_Klasse" HeaderText="S_K_Klasse" SortExpression="S_K_Klasse" />
</Columns>
</asp:GridView>
<asp:SqlDataSource ID="SqlDataSource1schueler" runat="server" ConflictDetection="CompareAllValues" ConnectionString="<%$ ConnectionStrings:ConnectionString %>" DeleteCommand="DELETE FROM [schueler] WHERE [S_SCHNR] = #original_S_SCHNR AND (([S_Name] = #original_S_Name) OR ([S_Name] IS NULL AND #original_S_Name IS NULL)) AND (([S_Vorname] = #original_S_Vorname) OR ([S_Vorname] IS NULL AND #original_S_Vorname IS NULL)) AND (([S_Gebdat] = #original_S_Gebdat) OR ([S_Gebdat] IS NULL AND #original_S_Gebdat IS NULL)) AND (([S_Adresse] = #original_S_Adresse) OR ([S_Adresse] IS NULL AND #original_S_Adresse IS NULL)) AND (([S_K_Klasse] = #original_S_K_Klasse) OR ([S_K_Klasse] IS NULL AND #original_S_K_Klasse IS NULL))" InsertCommand="INSERT INTO [schueler] ([S_SCHNR], [S_Name], [S_Vorname], [S_Gebdat], [S_Adresse], [S_K_Klasse]) VALUES (#S_SCHNR, #S_Name, #S_Vorname, #S_Gebdat, #S_Adresse, #S_K_Klasse)" OldValuesParameterFormatString="original_{0}" SelectCommand="SELECT * FROM [schueler] WHERE ([S_K_Klasse] = #S_K_Klasse)" UpdateCommand="UPDATE [schueler] SET [S_Name] = #S_Name, [S_Vorname] = #S_Vorname, [S_Gebdat] = #S_Gebdat, [S_Adresse] = #S_Adresse, [S_K_Klasse] = #S_K_Klasse WHERE [S_SCHNR] = #original_S_SCHNR AND (([S_Name] = #original_S_Name) OR ([S_Name] IS NULL AND #original_S_Name IS NULL)) AND (([S_Vorname] = #original_S_Vorname) OR ([S_Vorname] IS NULL AND #original_S_Vorname IS NULL)) AND (([S_Gebdat] = #original_S_Gebdat) OR ([S_Gebdat] IS NULL AND #original_S_Gebdat IS NULL)) AND (([S_Adresse] = #original_S_Adresse) OR ([S_Adresse] IS NULL AND #original_S_Adresse IS NULL)) AND (([S_K_Klasse] = #original_S_K_Klasse) OR ([S_K_Klasse] IS NULL AND #original_S_K_Klasse IS NULL))">
<DeleteParameters>
<asp:Parameter Name="original_S_SCHNR" Type="Int16" />
<asp:Parameter Name="original_S_Name" Type="String" />
<asp:Parameter Name="original_S_Vorname" Type="String" />
<asp:Parameter Name="original_S_Gebdat" Type="DateTime" />
<asp:Parameter Name="original_S_Adresse" Type="String" />
<asp:Parameter Name="original_S_K_Klasse" Type="String" />
</DeleteParameters>
<InsertParameters>
<asp:Parameter Name="S_SCHNR" Type="Int16" />
<asp:Parameter Name="S_Name" Type="String" />
<asp:Parameter Name="S_Vorname" Type="String" />
<asp:Parameter Name="S_Gebdat" Type="DateTime" />
<asp:Parameter Name="S_Adresse" Type="String" />
<asp:Parameter Name="S_K_Klasse" Type="String" />
</InsertParameters>
<SelectParameters>
<asp:ControlParameter ControlID="selectklassen" Name="S_K_Klasse" PropertyName="SelectedValue" Type="String" />
</SelectParameters>
<UpdateParameters>
<asp:Parameter Name="S_Name" Type="String" />
<asp:Parameter Name="S_Vorname" Type="String" />
<asp:Parameter Name="S_Gebdat" Type="DateTime" />
<asp:Parameter Name="S_Adresse" Type="String" />
<asp:Parameter Name="S_K_Klasse" Type="String" />
<asp:Parameter Name="original_S_SCHNR" Type="Int16" />
<asp:Parameter Name="original_S_Name" Type="String" />
<asp:Parameter Name="original_S_Vorname" Type="String" />
<asp:Parameter Name="original_S_Gebdat" Type="DateTime" />
<asp:Parameter Name="original_S_Adresse" Type="String" />
<asp:Parameter Name="original_S_K_Klasse" Type="String" />
</UpdateParameters>
</asp:SqlDataSource>

Make the student name column a Hyperlink column like this:
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" DataKeyNames="S_SCHNR" DataSourceID="SqlDataSource1schueler">
<Columns>
<asp:HyperLinkField DataNavigateUrlFields="S_SCHNR"
DataNavigateUrlFormatString="StudentInfo.aspx?id={0}
DataTextField="S_Name" "/>
<asp:BoundField DataField="S_SCHNR" HeaderText="S_SCHNR" ReadOnly="True" SortExpression="S_SCHNR" />
<asp:BoundField DataField="S_Name" HeaderText="S_Name" SortExpression="S_Name" />
<asp:BoundField DataField="S_Vorname" HeaderText="S_Vorname" SortExpression="S_Vorname" />
<asp:BoundField DataField="S_Gebdat" HeaderText="S_Gebdat" SortExpression="S_Gebdat" />
<asp:BoundField DataField="S_Adresse" HeaderText="S_Adresse" SortExpression="S_Adresse" />
<asp:BoundField DataField="S_K_Klasse" HeaderText="S_K_Klasse" SortExpression="S_K_Klasse" />
</Columns>
</asp:GridView>
Make another web page called StudentInfo.aspx. On that page, display the data using a DetailsView control, a SqlDataSource control and the QueryString parameter. Here's an example of how to do that: http://msdn.microsoft.com/en-us/library/xt50s8kz(v=vs.100).aspx

A more convenient way to do this without creating a new page would be to populate the data into a Bootstrap modal like this. It uses UpdatePanel, which may or may not be something you want to use though.
Add the Detail Event to the Gridview.
Create a div for the Bootstrap modal with a FormView
Call the jQuery from the C# code behind to populate the data in the FormView with the ID from the GridView.

Related

How to make new command work in gridview asp.net

I have a gridview, in the gridview task, I choose Edit Column-> Selected Fields->Command Field.select insert button to True. And the New link field appear, and I check the HTML Source,
look like necessary codes are there, but when I click on the "New" link field, no response at all, but update is ok for me, delete I have not tested yet.
Below are codes for the gridview and sqldatasource :
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" DataKeyNames="agreement_no,id" Font-Size="9pt" DataSourceID="SqlDataSource1" OnRowUpdated="GridView1_RowUpdated" OnRowUpdating="GridView1_RowUpdating" OnRowCreated="GridView1_RowCreated">
<Columns>
<asp:CommandField ShowDeleteButton="True" ShowEditButton="True" ShowInsertButton="True"></asp:CommandField>
<asp:BoundField DataField="agreement_no" HeaderText="agreement_no" ReadOnly="True" SortExpression="agreement_no"></asp:BoundField>
<asp:TemplateField HeaderText="status" SortExpression="status">
<EditItemTemplate>
<asp:DropDownList ID="DropDownList1" runat="server" DataSourceID="SqlDataSource2" DataTextField="status" DataValueField="status" SelectedValue='<%# Bind("status") %>'>
</asp:DropDownList>
<asp:SqlDataSource ID="SqlDataSource2" runat="server" ConnectionString="<%$ ConnectionStrings:GPGConnectionString %>" SelectCommand="SELECT DISTINCT [status] FROM [deal_master]"></asp:SqlDataSource>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="Label1" runat="server" Text='<%# Bind("status") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="sales_person" HeaderText="sales_person" SortExpression="sales_person"></asp:BoundField>
<asp:BoundField DataField="swap_carrier" HeaderText="swap_carrier" SortExpression="swap_carrier"></asp:BoundField>
<asp:BoundField DataField="start_pos" HeaderText="start_pos" SortExpression="start_pos"></asp:BoundField>
<asp:BoundField DataField="end_pos" HeaderText="end_pos" SortExpression="end_pos"></asp:BoundField>
<asp:BoundField DataField="swap_commitment" HeaderText="swap_commitment" SortExpression="swap_commitment"></asp:BoundField>
<asp:BoundField DataField="zone" HeaderText="zone" SortExpression="zone"></asp:BoundField>
<asp:BoundField DataField="target_minutes" HeaderText="target_minutes" SortExpression="target_minutes"></asp:BoundField>
<asp:BoundField DataField="target_sell_rate" HeaderText="target_sell_rate" SortExpression="target_sell_rate"></asp:BoundField>
<asp:BoundField DataField="target_buy_rate" HeaderText="target_buy_rate" SortExpression="target_buy_rate"></asp:BoundField>
<asp:BoundField ConvertEmptyStringToNull="false" DataField="supplier_interconnect" HeaderText="supplier_interconnect" SortExpression="supplier_interconnect"></asp:BoundField>
<asp:BoundField ConvertEmptyStringToNull="false" DataField="customer_interconnect" HeaderText="customer_interconnect" SortExpression="customer_interconnect"></asp:BoundField>
<asp:BoundField DataField="target_sales" HeaderText="target_sales" SortExpression="target_sales"></asp:BoundField>
<asp:BoundField DataField="target_cost" HeaderText="target_cost" SortExpression="target_cost"></asp:BoundField>
<asp:BoundField DataField="target_profit" HeaderText="target_profit" SortExpression="target_profit"></asp:BoundField>
<asp:BoundField DataField="lcr_zone" HeaderText="lcr_zone" SortExpression="lcr_zone"></asp:BoundField>
<asp:BoundField DataField="id" HeaderText="id" SortExpression="id" ReadOnly="True"></asp:BoundField>
</Columns>
</asp:GridView>
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:GPGConnectionString %>" DeleteCommand="DELETE FROM [deal_master] WHERE [agreement_no] = #agreement_no AND [id] = #id" InsertCommand="INSERT INTO [deal_master] ([agreement_no], [status], [sales_person], [swap_carrier], [start_pos], [end_pos], [swap_commitment], [zone], [target_minutes], [target_sell_rate], [target_buy_rate], [supplier_interconnect], [customer_interconnect], [target_sales], [target_cost], [target_profit], [lcr_zone], [id]) VALUES (#agreement_no, #status, #sales_person, #swap_carrier, #start_pos, #end_pos, #swap_commitment, #zone, #target_minutes, #target_sell_rate, #target_buy_rate, #supplier_interconnect, #customer_interconnect, #target_sales, #target_cost, #target_profit, #lcr_zone, #id)" SelectCommand="SELECT [agreement_no], [status], [sales_person], [swap_carrier], [start_pos], [end_pos], [swap_commitment], [zone], [target_minutes], [target_sell_rate], [target_buy_rate], [supplier_interconnect], [customer_interconnect], [target_sales], [target_cost], [target_profit], [lcr_zone], [id] FROM [deal_master]" UpdateCommand="UPDATE [deal_master] SET [status] = #status, [sales_person] = #sales_person, [swap_carrier] = #swap_carrier, [start_pos] = #start_pos, [end_pos] = #end_pos, [swap_commitment] = #swap_commitment, [zone] = #zone, [target_minutes] = #target_minutes, [target_sell_rate] = #target_sell_rate, [target_buy_rate] = #target_buy_rate, [supplier_interconnect] = #supplier_interconnect, [customer_interconnect] = #customer_interconnect, [target_sales] = #target_sales, [target_cost] = #target_cost, [target_profit] = #target_profit, [lcr_zone] = #lcr_zone WHERE [agreement_no] = #agreement_no AND [id] = #id">
<DeleteParameters>
<asp:Parameter Name="agreement_no" Type="String" />
<asp:Parameter Name="id" Type="Int32" />
</DeleteParameters>
<InsertParameters>
<asp:Parameter Name="agreement_no" Type="String" />
<asp:Parameter Name="status" Type="String" />
<asp:Parameter Name="sales_person" Type="String" />
<asp:Parameter Name="swap_carrier" Type="String" />
<asp:Parameter Name="start_pos" Type="Decimal" />
<asp:Parameter Name="end_pos" Type="Decimal" />
<asp:Parameter Name="swap_commitment" Type="String" />
<asp:Parameter Name="zone" Type="String" />
<asp:Parameter Name="target_minutes" Type="Decimal" />
<asp:Parameter Name="target_sell_rate" Type="Decimal" />
<asp:Parameter Name="target_buy_rate" Type="Decimal" />
<asp:Parameter Name="supplier_interconnect" Type="String" />
<asp:Parameter ConvertEmptyStringToNull="false" Name="customer_interconnect" Type="String" />
<asp:Parameter Name="target_sales" Type="Decimal" />
<asp:Parameter Name="target_cost" Type="Decimal" />
<asp:Parameter Name="target_profit" Type="Decimal" />
<asp:Parameter Name="lcr_zone" Type="String" />
<asp:Parameter Name="id" Type="Int32" />
</InsertParameters>
<UpdateParameters>
<asp:Parameter Name="status" Type="String" />
<asp:Parameter Name="sales_person" Type="String" />
<asp:Parameter Name="swap_carrier" Type="String" />
<asp:Parameter Name="start_pos" Type="Decimal" />
<asp:Parameter Name="end_pos" Type="Decimal" />
<asp:Parameter Name="swap_commitment" Type="String" />
<asp:Parameter Name="zone" Type="String" />
<asp:Parameter Name="target_minutes" Type="Decimal" />
<asp:Parameter Name="target_sell_rate" Type="Decimal" />
<asp:Parameter Name="target_buy_rate" Type="Decimal" />
<asp:Parameter ConvertEmptyStringToNull="false" Name="supplier_interconnect" Type="String" />
<asp:Parameter ConvertEmptyStringToNull="false" Name="customer_interconnect" Type="String" />
<asp:Parameter Name="target_sales" Type="Decimal" />
<asp:Parameter Name="target_cost" Type="Decimal" />
<asp:Parameter Name="target_profit" Type="Decimal" />
<asp:Parameter Name="lcr_zone" Type="String" />
<asp:Parameter Name="agreement_no" Type="String" />
<asp:Parameter Name="id" Type="Int32" />
</UpdateParameters>
</asp:SqlDataSource>
<asp:SqlDataSource ID="SqlDataSource3" runat="server" ConnectionString="<%$ ConnectionStrings:GPGConnectionString %>" SelectCommand="SELECT DISTINCT [agreement_no] FROM [deal_master] ORDER BY [agreement_no]"></asp:SqlDataSource>
<br />
<br />
<div>
</div>
enter image description here
my question is : what is the actions or setting I missed?
I want to know what steps I missed?
My objective is : I want to click on the "New" linkfield then 1 empty row appear, then I input the value in the new created row and I can save it or cancel it
If you look at the documentation for the GridView control, it says:
Inserting records into the data source is not directly supported by the GridView control. However, it is possible to insert records by using the GridView control in conjunction with the DetailsView or FormView control. For more information, see DetailsView or FormView, respectively.
Additionally, the CommandField documentation states about the ShowInsertButton property:
This property applies only to data-bound controls that support insert operations, such as the DetailsView control.
So, you'll need to create your own form separately, or leverage a DetailsView or FormView. Or better yet: ditch Web Forms altogether if you can, as it's a dead platform, as I explain on my blog.

Conversion from type 'DBNull' to type 'Integer' is not valid. using asp.net and object data source

im try to edit row in gridview called(gvTeam)
the gridview using objectdatasource(odsGvTeam)
in Admin_team.aspx
<asp:GridView ID="gvTeam" runat="server" AutoGenerateColumns="False" DataKeyNames="team_id" DataSourceID="odsGvTeam" AllowPaging="True">
<Columns>
<asp:BoundField DataField="team_id" HeaderText="team_id" InsertVisible="False" ReadOnly="True" SortExpression="team_id" Visible="False" />
<asp:BoundField DataField="team_name" HeaderText="key_team_name" SortExpression="team_name" />
<asp:BoundField DataField="team_lang" HeaderText="key_team_lang" SortExpression="team_lang" />
<asp:BoundField DataField="team_status" HeaderText="key_status" SortExpression="team_status" />
<asp:BoundField DataField="team_key" HeaderText="key_team_key" SortExpression="team_key" />
<asp:BoundField DataField="team_rating" HeaderText="key_team_rating" SortExpression="team_rating" />
<asp:TemplateField ShowHeader="False">
<ItemTemplate>
<asp:LinkButton ID="lnkEditTeam" runat="server" CausesValidation="false" CommandName="edit_team" Text="Edit" CommandArgument='<%# Bind("team_id") %>'></asp:LinkButton>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField>
<ItemTemplate>
<asp:LinkButton ID="lnkDeleteTeam" runat="server" CausesValidation="false" OnClientClick="return confirm('Are you sure?');" CommandName="delete_team" Text="Delete" CommandArgument='<%# Bind("team_id") %>'></asp:LinkButton>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
<asp:ObjectDataSource ID="odsGvTeam" runat="server" DeleteMethod="Delete" InsertMethod="Insert" OldValuesParameterFormatString="original_{0}" SelectMethod="GetData" TypeName="CMS_NG_Sql_V1.dsTeamTableAdapters.taTeam" UpdateMethod="Update">
<DeleteParameters>
<asp:Parameter Name="original_team_id" Type="Int32" />
</DeleteParameters>
<InsertParameters>
<asp:Parameter Name="team_name" Type="String" />
<asp:Parameter Name="team_lang" Type="String" />
<asp:Parameter Name="team_status" Type="Int32" />
<asp:Parameter Name="team_key" Type="String" />
<asp:Parameter Name="team_rating" Type="Int32" />
</InsertParameters>
<SelectParameters>
<asp:Parameter DefaultValue="en" Name="team_lang" Type="String" />
</SelectParameters>
<UpdateParameters>
<asp:Parameter Name="team_name" Type="String" />
<asp:Parameter Name="team_lang" Type="String" />
<asp:Parameter Name="team_status" Type="Int32" />
<asp:Parameter Name="team_key" Type="String" />
<asp:Parameter Name="team_rating" Type="Int32" />
<asp:Parameter Name="team_id" Type="Int32" />
</UpdateParameters>
</asp:ObjectDataSource>
CodeBehing
Protected Sub gvTeam_RowCommand(sender As Object, e As GridViewCommandEventArgs) Handles gvTeam.RowCommand
Select Case e.CommandName.ToLower
Case "edit_team"
txtID.Value = e.CommandArgument
Using objTeam As New cls_Team(CInt(txtID.Value))
txtID.Value = objTeam.TeamDataRow.team_id
txtLang.Text = objTeam.TeamDataRow.team_lang
txtRating.Text = objTeam.TeamDataRow.team_rating
txtTeamKey.Text = objTeam.TeamDataRow.team_key
optStatus.SelectedValue = objTeam.TeamDataRow.team_status
txtName.Text = objTeam.TeamDataRow.team_name
MultiView1.SetActiveView(viwEditTeam)
End Using
AdminLogFile(CMS_NG_Sql_V1.enum_AdminLogFile.Edit)
Case "delete_team"
Dim intID As Integer = e.CommandArgument
'Response.Redirect("admin_team.aspx?IDTeam=" & intID)
Using objTeam As New cls_Team(intID)
objTeam.Delete(intID)
AdminLogFile(CMS_NG_Sql_V1.enum_AdminLogFile.Delete)
gvTeam.DataBind()
End Using
End Select
End Sub
the Case "delete_team" work fine
but the Case "edit_team" not worked
i got error:
also i used dataset called (dsTeam.xsd)
how can solved IT ?
A value in the team_rating column is NULL. A database NULL different from a string variable in VB that may have a null value. You need to check for this before assigning a value to txtRating.Text:
If Not objTeam.TeamDataRow.IsNull("team_rating") Then
txtRating.Text = objTeam.TeamDataRow.team_rating
End If

GridView is not displaying when page is loaded

Hello I am working on a project for school. I am building a page that has a DropDownList that is populated through a SQLDataSource. It displays the names of classes from a table in my database called 'COURSES', when one of the classes is selected a GridView is supposed to display data from tables 'STUDENTS' and 'GRADES'. When I make a selection the GridView does not display at all. I think the problem is in my WHERE clause of the SELECT command. Any help would be greatly appreciated!
Here is my aspx file:
<%# Page Language="C#" AutoEventWireup="true" CodeFile="ClassStudentEdit.aspx.cs" Inherits="ClassStudentEdit" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Students</title>
<link type="text/css" rel="stylesheet" href="termproject.css" />
</head>
<body>
<form id="form1" runat="server">
<div id="main">
Course Name: <asp:DropDownList ID="DropDownList1" runat="server" AutoPostBack="True" DataSourceID="SqlDataSource1" DataTextField="CourseName" DataValueField="CourseID"></asp:DropDownList>
<br />
<br />
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:PayablesConnectionString %>" SelectCommand="SELECT [CourseName], [CourseID] FROM [COURSES] ORDER BY [CourseName]"></asp:SqlDataSource>
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" DataSourceID="SqlDataSource2" DataKeyNames="CourseID" AllowPaging="True" AllowSorting="True">
<Columns>
<asp:CommandField ButtonType="Button" ShowSelectButton="True" />
<asp:BoundField DataField="StudentID" HeaderText="StudentID" SortExpression="StudentID" InsertVisible="False" ReadOnly="True" />
<asp:BoundField DataField="Title" HeaderText="Title" SortExpression="Title" />
<asp:BoundField DataField="FirstName" HeaderText="FirstName" SortExpression="FirstName" />
<asp:BoundField DataField="LastName" HeaderText="LastName" SortExpression="LastName" />
<asp:BoundField DataField="Grade" HeaderText="Grade" SortExpression="Grade" />
</Columns>
</asp:GridView>
<br />
<asp:SqlDataSource ID="SqlDataSource2" runat="server" ConnectionString="<%$ ConnectionStrings:PayablesConnectionString %>" SelectCommand="SELECT COURSES.CourseID, GRADES.Grade, STUDENTS.StudentID, STUDENTS.Title, STUDENTS.FirstName, STUDENTS.LastName FROM COURSES INNER JOIN GRADES ON COURSES.CourseID = GRADES.CourseID INNER JOIN STUDENTS ON GRADES.StudentID = STUDENTS.StudentID WHERE (COURSES.CourseName = #CourseID)">
<SelectParameters>
<asp:ControlParameter ControlID="DropDownList1" Name="CourseID" PropertyName="SelectedValue" />
</SelectParameters>
</asp:SqlDataSource>
<asp:DetailsView ID="DetailsView1" runat="server" Height="50px" Width="125px" AutoGenerateRows="False" DataKeyNames="StudentID" DataSourceID="SqlDataSource3">
<Fields>
<asp:BoundField DataField="StudentID" HeaderText="StudentID" InsertVisible="False" ReadOnly="True" SortExpression="StudentID" />
<asp:BoundField DataField="Title" HeaderText="Title" SortExpression="Title" />
<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:CommandField ShowEditButton="True" />
</Fields>
</asp:DetailsView>
<asp:SqlDataSource ID="SqlDataSource3" runat="server" ConflictDetection="CompareAllValues" ConnectionString="<%$ ConnectionStrings:PayablesConnectionString %>" DeleteCommand="DELETE FROM [STUDENTS] WHERE [StudentID] = #original_StudentID AND (([Title] = #original_Title) OR ([Title] IS NULL AND #original_Title IS NULL)) AND (([FirstName] = #original_FirstName) OR ([FirstName] IS NULL AND #original_FirstName IS NULL)) AND (([LastName] = #original_LastName) OR ([LastName] IS NULL AND #original_LastName IS NULL)) AND (([Address] = #original_Address) OR ([Address] IS NULL AND #original_Address IS NULL))" InsertCommand="INSERT INTO [STUDENTS] ([Title], [FirstName], [LastName], [Address]) VALUES (#Title, #FirstName, #LastName, #Address)" OldValuesParameterFormatString="original_{0}" SelectCommand="SELECT * FROM [STUDENTS] WHERE ([StudentID] = #StudentID)" UpdateCommand="UPDATE [STUDENTS] SET [Title] = #Title, [FirstName] = #FirstName, [LastName] = #LastName, [Address] = #Address WHERE [StudentID] = #original_StudentID AND (([Title] = #original_Title) OR ([Title] IS NULL AND #original_Title IS NULL)) AND (([FirstName] = #original_FirstName) OR ([FirstName] IS NULL AND #original_FirstName IS NULL)) AND (([LastName] = #original_LastName) OR ([LastName] IS NULL AND #original_LastName IS NULL)) AND (([Address] = #original_Address) OR ([Address] IS NULL AND #original_Address IS NULL))">
<DeleteParameters>
<asp:Parameter Name="original_StudentID" Type="Int32" />
<asp:Parameter Name="original_Title" Type="String" />
<asp:Parameter Name="original_FirstName" Type="String" />
<asp:Parameter Name="original_LastName" Type="String" />
<asp:Parameter Name="original_Address" Type="String" />
</DeleteParameters>
<InsertParameters>
<asp:Parameter Name="Title" Type="String" />
<asp:Parameter Name="FirstName" Type="String" />
<asp:Parameter Name="LastName" Type="String" />
<asp:Parameter Name="Address" Type="String" />
</InsertParameters>
<SelectParameters>
<asp:ControlParameter ControlID="GridView1" Name="StudentID" PropertyName="SelectedValue" Type="Int32" />
</SelectParameters>
<UpdateParameters>
<asp:Parameter Name="Title" Type="String" />
<asp:Parameter Name="FirstName" Type="String" />
<asp:Parameter Name="LastName" Type="String" />
<asp:Parameter Name="Address" Type="String" />
<asp:Parameter Name="original_StudentID" Type="Int32" />
<asp:Parameter Name="original_Title" Type="String" />
<asp:Parameter Name="original_FirstName" Type="String" />
<asp:Parameter Name="original_LastName" Type="String" />
<asp:Parameter Name="original_Address" Type="String" />
</UpdateParameters>
</asp:SqlDataSource>
<br />
<br />
</div>
</form>
</body>
</html>
This is your sql:
SELECT Courses.Courseid,
Grades.Grade,
Students.Studentid,
Students.Title,
Students.Firstname,
Students.Lastname
FROM Courses
INNER JOIN Grades
ON Courses.Courseid = Grades.Courseid
INNER JOIN Students
ON Grades.Studentid = Students.Studentid
WHERE ( Courses.Coursename = #CourseID )
Isn't it Courses.Courseid instead of Courses.Coursename? So:
WHERE ( Courses.Courseid = #CourseID )
( one of the reasons why i avoid declarative datasource controls )

asp.net access database not updating

I am trying to update values in my access database, however it does not work in some cases.
The code :
<form id="form1" runat="server">
<asp:AccessDataSource ID="AccessDataSource1" runat="server"
DataFile="~/App_Data/Database1.mdb"
DeleteCommand="UPDATE DT_Person SET Deleted = NOW() WHERE (Person_Ref = ?)"
InsertCommand="INSERT INTO [DT_Person] ([Person_Ref], [Created], [Updated], [Deleted], [Person_Name], [Person_No]) VALUES (?, ?, ?, ?, ?, ?)"
OldValuesParameterFormatString="original_{0}"
SelectCommand="SELECT * FROM [DT_Person]"
UpdateCommand="UPDATE DT_Person SET Updated = NOW(), Person_Name = ?, Person_No = ? WHERE (Person_Ref = ?)">
<DeleteParameters>
<asp:Parameter Name="original_Person_Ref" Type="Int32" />
</DeleteParameters>
<UpdateParameters>
<asp:Parameter Name="Created" Type="DateTime" />
<asp:Parameter Name="Updated" Type="DateTime" />
<asp:Parameter Name="Deleted" Type="DateTime" />
<asp:Parameter Name="Person_Name" Type="String" />
<asp:Parameter Name="Person_No" Type="String" />
<asp:Parameter Name="original_Person_Ref" Type="Int32" />
</UpdateParameters>
<InsertParameters>
<asp:Parameter Name="Person_Ref" Type="Int32" />
<asp:Parameter Name="Created" Type="DateTime" />
<asp:Parameter Name="Updated" Type="DateTime" />
<asp:Parameter Name="Deleted" Type="DateTime" />
<asp:Parameter Name="Person_Name" Type="String" />
<asp:Parameter Name="Person_No" Type="String" />
</InsertParameters>
</asp:AccessDataSource>
<asp:GridView ID="GridView1" runat="server" AllowPaging="True"
AllowSorting="True" AutoGenerateColumns="False" BackColor="White"
BorderColor="#CCCCCC" BorderStyle="None" BorderWidth="1px" CellPadding="3"
DataKeyNames="Person_Ref" DataSourceID="AccessDataSource1">
<RowStyle ForeColor="#000066" />
<Columns>
<asp:CommandField ShowDeleteButton="True" ShowEditButton="True"
ShowSelectButton="True" />
<asp:BoundField DataField="Person_Ref" HeaderText="Person_Ref"
InsertVisible="False" ReadOnly="True" SortExpression="Person_Ref" />
<asp:BoundField DataField="Created" HeaderText="Created"
SortExpression="Created" />
<asp:BoundField DataField="Updated" HeaderText="Updated"
SortExpression="Updated" />
<asp:BoundField DataField="Deleted" HeaderText="Deleted"
SortExpression="Deleted" />
<asp:BoundField DataField="Person_Name" HeaderText="Person_Name"
SortExpression="Person_Name" />
<asp:BoundField DataField="Person_No" HeaderText="Person_No"
SortExpression="Person_No" />
</Columns>
As you can see, the delete command
(DeleteCommand="UPDATE DT_Person SET Deleted = NOW() WHERE (Person_Ref = ?)" )
is really an update statement and this works fine . However the actual update statement does not work on the web page. The weird thing is, if you test the query in the 'query builder' it works fine.
Really need some help here.
TIA
P.S. Im using Visual Studio 2008 and using the data source builder each time
Windows 7 (if that's what you're using) has been known to make a copy of Access databases down in the Debug files and use the copy for all data changes. You might want to check that the database you are actually accessing is the copy you think it is.
Do a search for files with the same name across your whole development machine. You might be surprised what turns up.

Can not update Column bound by an Image field in gridview asp.net

I have three columns in my Grid view named TweetText, TweetImageUrl and an Column of ImageFied
whose DataImageUrl Field is TweetImageURl. My problem is that When i use the Edit,update feature of grid, I cant edit/update the TweetImageUrl but I can Update TweetText. But when I remove The ImageField Column then I can update the TweetImageUrl Column too. So Can anyone help so that i can Update the TweetImageUrl with ImageField there in Grid Too?
<asp:GridView ID="GridView1" runat="server" AllowPaging="True"
AutoGenerateColumns="False" DataKeyNames="TwitterUserId"
DataSourceID="SqlDataSource1" onrowcommand="GridView1_RowCommand"
PageSize="14" >
<Columns>
<asp:CommandField ShowDeleteButton="True" ShowEditButton="True" />
<asp:TemplateField>
<ItemTemplate>
<asp:LinkButton ID="Approve" runat="server"
CommandName="Approve"
CommandArgument="<%# ((GridViewRow) Container).RowIndex %>"
Text="Approve" />
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="TweetText" HeaderText="TweetText"
SortExpression="TweetText" />
<asp:BoundField DataField="TweetImageUrl" HeaderText="TweetImageUrl"
SortExpression="TweetImageUrl" />
<asp:ImageField DataImageUrlField="TweetImageUrl" HeaderText="Images" ItemStyle-Height = "10px" ItemStyle-Width = "10px"
NullImageUrl="~/Admin/ajax-loader.gif">
</asp:ImageField>
</Columns>
<PagerSettings Mode="NextPreviousFirstLast" />
</asp:GridView>
<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConflictDetection="CompareAllValues"
ConnectionString="<%$ ConnectionStrings:mistersmartyplantsConnectionString %>"
DeleteCommand="DELETE FROM [TwitterData] WHERE [TwitterUserId] = #original_TwitterUserId AND (([TweetId] = #original_TweetId) OR ([TweetId] IS NULL AND #original_TweetId IS NULL)) AND (([TwitterUserName] = #original_TwitterUserName) OR ([TwitterUserName] IS NULL AND #original_TwitterUserName IS NULL)) AND (([TweetText] = #original_TweetText) OR ([TweetText] IS NULL AND #original_TweetText IS NULL)) AND (([TweetImageUrl] = #original_TweetImageUrl) OR ([TweetImageUrl] IS NULL AND #original_TweetImageUrl IS NULL)) AND (([TwitterDate] = #original_TwitterDate) OR ([TwitterDate] IS NULL AND #original_TwitterDate IS NULL))"
InsertCommand="INSERT INTO [TwitterData] ([TweetId], [TwitterUserId], [TwitterUserName], [TweetText], [TweetImageUrl], [TwitterDate]) VALUES (#TweetId, #TwitterUserId, #TwitterUserName, #TweetText, #TweetImageUrl, #TwitterDate)"
OldValuesParameterFormatString="original_{0}"
SelectCommand="SELECT [TweetId], [TwitterUserId], [TwitterUserName], [TweetText], [TweetImageUrl], [TwitterDate] FROM [TwitterData] WHERE ([Approved] = #Approved) ORDER BY [TwitterDate] DESC"
UpdateCommand="UPDATE [TwitterData] SET [TweetId] = #TweetId, [TwitterUserName] = #TwitterUserName, [TweetText] = #TweetText, [TweetImageUrl] = #TweetImageUrl, [TwitterDate] = #TwitterDate WHERE [TwitterUserId] = #original_TwitterUserId AND (([TweetId] = #original_TweetId) OR ([TweetId] IS NULL AND #original_TweetId IS NULL)) AND (([TwitterUserName] = #original_TwitterUserName) OR ([TwitterUserName] IS NULL AND #original_TwitterUserName IS NULL)) AND (([TweetText] = #original_TweetText) OR ([TweetText] IS NULL AND #original_TweetText IS NULL)) AND (([TweetImageUrl] = #original_TweetImageUrl) OR ([TweetImageUrl] IS NULL AND #original_TweetImageUrl IS NULL)) AND (([TwitterDate] = #original_TwitterDate) OR ([TwitterDate] IS NULL AND #original_TwitterDate IS NULL))">
<DeleteParameters>
<asp:Parameter Name="original_TwitterUserId" Type="String" />
<asp:Parameter Name="original_TweetId" Type="String" />
<asp:Parameter Name="original_TwitterUserName" Type="String" />
<asp:Parameter Name="original_TweetText" Type="String" />
<asp:Parameter Name="original_TweetImageUrl" Type="String" />
<asp:Parameter Name="original_TwitterDate" Type="String" />
</DeleteParameters>
<InsertParameters>
<asp:Parameter Name="TweetId" Type="String" />
<asp:Parameter Name="TwitterUserId" Type="String" />
<asp:Parameter Name="TwitterUserName" Type="String" />
<asp:Parameter Name="TweetText" Type="String" />
<asp:Parameter Name="TweetImageUrl" Type="String" />
<asp:Parameter Name="TwitterDate" Type="String" />
</InsertParameters>
<SelectParameters>
<asp:Parameter DefaultValue="No" Name="Approved" Type="String" />
</SelectParameters>
<UpdateParameters>
<asp:Parameter Name="TweetId" Type="String" />
<asp:Parameter Name="TwitterUserName" Type="String" />
<asp:Parameter Name="TweetText" Type="String" />
<asp:Parameter Name="TweetImageUrl" Type="String" />
<asp:Parameter Name="TwitterDate" Type="String" />
<asp:Parameter Name="original_TwitterUserId" Type="String" />
<asp:Parameter Name="original_TweetId" Type="String" />
<asp:Parameter Name="original_TwitterUserName" Type="String" />
<asp:Parameter Name="original_TweetText" Type="String" />
<asp:Parameter Name="original_TweetImageUrl" Type="String" />
<asp:Parameter Name="original_TwitterDate" Type="String" />
</UpdateParameters>
</asp:SqlDataSource>
Use
<asp:TemplateField HeaderText="Images" ItemStyle-Height="10px" ItemStyle-Width="10px" >
<ItemTemplate>
<asp:Image ID="Image1" runat="server" ImageUrl='<%# Eval(TweetImageUrl) %>' Height="10px" Width="10px" />
</ItemTemplate>
</asp:TemplateField>
Rather then
<asp:ImageField DataImageUrlField="TweetImageUrl" HeaderText="Images" ItemStyle-Height = "10px" ItemStyle-Width = "10px" NullImageUrl="~/Admin/ajax-loader.gif"></asp:ImageField>
Hope It Helps. Good Luck.

Resources