I put gridview and I added hyperlink to take the user to other page and changed the status id based on a query but the problem that the update query is not worked even no error:
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" DataSourceID="SqlDataSource1" style="margin:auto" >
<Columns>
<asp:TemplateField HeaderText="user enter">
<ItemTemplate>
<asp:HyperLink ID="HyperLink1" runat="server" NavigateUrl='<%# String.Format("~/entry.aspx?request_id={0}",DataBinder.Eval (Container,"DataItem.request_id"))%>' >
enter </asp:HyperLink>
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="name" HeaderText="name" ReadOnly="True" SortExpression="name" />
<asp:BoundField DataField="visitor_mobile" HeaderText="visitor_mobile" SortExpression="visitor_mobile" />
<asp:BoundField DataField="request_id" HeaderText="request_id" InsertVisible="False" ReadOnly="True" SortExpression="request_id" />
<asp:BoundField DataField="request_date" HeaderText="request_date" SortExpression="request_date" />
<asp:BoundField DataField="visit_date" HeaderText="visit_date" SortExpression="visit_date" />
<asp:BoundField DataField="reason" HeaderText="reason" SortExpression="reason" />
<asp:BoundField DataField="status_name" HeaderText="status_name" SortExpression="status_name" />
</Columns>
</asp:GridView>
and this is the code when user click enter it query to update the status_id:
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:visitormanagementConnectionString %>" SelectCommand="update dbo.requests set status_id=5
where request_id= #request_id;" UpdateCommand="update dbo.requests set status_id=5 where request_id= #request_id">
<SelectParameters>
<asp:QueryStringParameter Name="request_id" QueryStringField="request_id" />
</SelectParameters>
<UpdateParameters>
<asp:Parameter Name="request_id" />
</UpdateParameters>
</asp:SqlDataSource>
Related
I have a Gridview control that I'm trying to allow the users to use the delete button to delete the record from the database. When I click the delete button, it tells me that there is no value for the parameter. Here is the relevant markup:
<asp:AccessDataSource ID="AccessDataSource1" runat="server"
DataFile="~/App_Data/webvideos.mdb"
SelectCommand="SELECT Org_Sec_Atty.ID, ORGANIZATIONS.ORG_NAME, ORG_SECTIONS.SectionName, ATTORNEYS.NAME, ATTORNEYS.LASTNAME, ATTORNEYS.EMAIL, ATTORNEYS.TEL
FROM (ORGANIZATIONS INNER JOIN (Org_Sec_Atty INNER JOIN ATTORNEYS ON Org_Sec_Atty.Atty_ID = ATTORNEYS.ATTY_ID) ON ORGANIZATIONS.ID = Org_Sec_Atty.OrgID) INNER JOIN ORG_SECTIONS ON Org_Sec_Atty.SecID = ORG_SECTIONS.ID;"
DeleteCommand="DELETE FROM Org_Sec_Atty WHERE ID = ?">
<DeleteParameters>
<asp:Parameter Name="ID" Type="Int32" />
</DeleteParameters>
</asp:AccessDataSource>
<asp:GridView ID="GridView1" runat="server" AllowPaging="True" PageSize="20"
AllowSorting="True" DataSourceID="AccessDataSource1" >
<Columns>
<asp:CommandField ShowDeleteButton="True" />
<asp:BoundField DataField="ID" HeaderText="ID" SortExpression="ID" />
<asp:BoundField DataField="ORG_NAME" HeaderText="Organization" SortExpression="ORG_NAME" />
<asp:BoundField DataField="SectionName" HeaderText="Section" SortExpression="SectionName" />
<asp:BoundField DataField="NAME" HeaderText="First Name" SortExpression="NAME" />
<asp:BoundField DataField="LASTNAME" HeaderText="Last Name" SortExpression="LASTNAME" />
<asp:BoundField DataField="EMAIL" HeaderText="E-mail" SortExpression="EMAIL" />
<asp:BoundField DataField="TEL" HeaderText="Phone" SortExpression="TEL" />
</Columns>
</asp:GridView>
I initially forgot to include the Org_Sec_Atty.ID in my SELECT statement and added it in there later when I clicked the delete button and nothing happened. I tried clearing my browser cache with no luck. Any other ideas?
I think that you also need to set the DataKeyNames property in the gridview:
<asp:GridView ID="GridView1" runat="server" AllowPaging="True" PageSize="20"
AllowSorting="True" DataSourceID="AccessDataSource1" DataKeyNames="ID" >
This should sort you out.
I use griview propertied while editing or deleting records without coding
When I click on edit button my image is also converted into a TextBox control,
I want to take
Fileupload control instead of textBox control.
For it which property shoule i set?
my code is as follow
<asp:GridView ID="GridView1" runat="server" Width="197px"
AutoGenerateColumns="False" DataKeyNames="ProductID"
DataSourceID="SqlDataSource2" AllowPaging="True">
<Columns>
<asp:BoundField DataField="ProductID" HeaderText="ProductID"
InsertVisible="False" ReadOnly="True" SortExpression="ProductID" />
<asp:BoundField DataField="ProductName" HeaderText="ProductName"
SortExpression="ProductName" />
<asp:ImageField DataImageUrlField="Image" HeaderText="PHOTO">
<ControlStyle Height="100px" Width="100px" />
</asp:ImageField>
<asp:BoundField DataField="Status" HeaderText="Status"
SortExpression="status" />
<asp:CommandField ShowEditButton="True" />
<asp:CommandField ShowDeleteButton="True" />
</Columns>
</asp:GridView>
And here is the code of SqlDataSource2:
<asp:SqlDataSource ID="SqlDataSource2" runat="server"
ConnectionString="<%$ ConnectionStrings:ConnectionStringnewdb %>"
DeleteCommand="delete from Product where ProductID=#ProductID"
SelectCommand="SELECT * FROM [Product]"
UpdateCommand="update Product set ProductName=#ProductName,Status=#Status where ProductID=#ProductID ">
<DeleteParameters>
<asp:ControlParameter ControlID="GridView1" Name="ProductID"
PropertyName="SelectedValue" />
</DeleteParameters>
<UpdateParameters>
<asp:ControlParameter ControlID="GridView1" Name="ProductName"
PropertyName="SelectedValue" />
<asp:Parameter Name="ProductID" />
</UpdateParameters>
</asp:SqlDataSource>
Use the EditItemTemplate and add the FileUpload control:
... other columns ...
</EditItemTemplate>
<ItemTemplate>
<asp:FileUpload id="FileUpload1" runat="server">
</asp:FileUpload>
</ItemTemplate>
</asp:TemplateField>
... other columns ...
Here's a tutorial: http://msdn.microsoft.com/en-us/library/ms972948.aspx
I'm building a GridView based on what is passed on the previous page querystring.
Is there a way to display a message saying 'no records found' if the GridView isn't populated? i.e. the query produces no records to populate the GridView.
code:
<div class="centergrid">
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False"
DataSourceID="SqlDataSource1" CssClass="bookgridview">
<Columns>
<asp:TemplateField HeaderText="Choose">
<ItemTemplate>
<asp:HyperLink ID="lnkSelect" runat='server' NavigateUrl='<%# String.Format("~/bookingform.aspx?ID={0}", Eval("ScheduleId")) %>'>Book</asp:HyperLink>
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="TName" HeaderText="Name" SortExpression="TName" />
<asp:BoundField DataField="SDate" HeaderText="Date" SortExpression="SDate" DataFormatString="{0:d}" />
<asp:BoundField DataField="STime" HeaderText="Time" SortExpression="STime" />
<asp:BoundField DataField="TPriceadult" HeaderText="Price (Adult)"
SortExpression="TPriceadult" DataFormatString="{0:C}" />
<asp:BoundField DataField="TPricesenior" HeaderText="Price (Student/Senior)"
SortExpression="TPricesenior" DataFormatString="{0:C}" />
<asp:BoundField DataField="TPricechild" HeaderText="Price (Child)"
SortExpression="Tpricechild" DataFormatString="{0:C}" />
<asp:BoundField DataField="TDuration" HeaderText="Duration"
SortExpression="TDuration" />
<asp:BoundField DataField="ScheduleId" HeaderText="ScheduleId"
SortExpression="ScheduleId" Visible="False" />
</Columns>
</asp:GridView>
<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="<%$ ConnectionStrings:ChinatowndbConnString %>"
SelectCommand="SELECT * FROM [vwSchedule] Where TourId=#tid">
<SelectParameters>
<asp:QueryStringParameter DbType="Int32" Name="tid" QueryStringField="tourid" />
</SelectParameters>
</asp:SqlDataSource>
Is there a way to display a message saying 'no records found' if the
GridView isn't populated?
Yes, with the EmptyDataTemplate.
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False"
DataSourceID="SqlDataSource1" CssClass="bookgridview">
<emptydatarowstyle backcolor="LightBlue"
forecolor="Red"/>
<emptydatatemplate>
<asp:image id="NoDataImage"
imageurl="~/images/Image.jpg"
alternatetext="No Image"
runat="server"/>
No records found.
</emptydatatemplate>
<Columns>
<asp:TemplateField HeaderText="Choose">
<ItemTemplate>
<asp:HyperLink ID="lnkSelect" runat='server' NavigateUrl='<%# String.Format("~/bookingform.aspx?ID={0}", Eval("ScheduleId")) %>'>Book</asp:HyperLink>
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="TName" HeaderText="Name" SortExpression="TName" />
<asp:BoundField DataField="SDate" HeaderText="Date" SortExpression="SDate" DataFormatString="{0:d}" />
<asp:BoundField DataField="STime" HeaderText="Time" SortExpression="STime" />
<asp:BoundField DataField="TPriceadult" HeaderText="Price (Adult)"
SortExpression="TPriceadult" DataFormatString="{0:C}" />
<asp:BoundField DataField="TPricesenior" HeaderText="Price (Student/Senior)"
SortExpression="TPricesenior" DataFormatString="{0:C}" />
<asp:BoundField DataField="TPricechild" HeaderText="Price (Child)"
SortExpression="Tpricechild" DataFormatString="{0:C}" />
<asp:BoundField DataField="TDuration" HeaderText="Duration"
SortExpression="TDuration" />
<asp:BoundField DataField="ScheduleId" HeaderText="ScheduleId"
SortExpression="ScheduleId" Visible="False" />
</Columns>
</asp:GridView>
Alternatively, you can use the built-in UI for the empty data row by setting the EmptyDataText property instead of this property.
I was assigned to convert some .Net projects in old version to to .net 4.0 version. I used ODAC driver replacing ODBC driver. Everything went fine until I found a problem with a gridview were I get illegal character Oracle exception when I try to delete a row. The gridview is inside an update panel. The exception I receive is Microsoft Jscript run time error:Sys.WebForms.PageRequestManagerServerErrorException: ORA-00911:invalid character. The following is the code for the grid view and the sqldatasource. The linkbutton triggers the delete using the deleteparameters of the sqldatasource.
<FooterStyle BackColor="#990000" Font-Bold="True" ForeColor="White" />
<Columns>
<asp:TemplateField HeaderText="View">
<ItemTemplate>
<asp:HyperLink ID="HyperLink1" runat="server" NavigateUrl='<%# Eval("CODE_OWNER_ID", "default.aspx?id={0}") %>'>View</asp:HyperLink>
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="CODE_OWNER_ID" Visible ="False" HeaderText="CODE OWNER ID" />
<asp:BoundField DataField="CODE_TYPE" ReadOnly ="True" HeaderText="CODE TYPE" />
<asp:BoundField DataField="CODE" ReadOnly="True" HeaderText="CODE" />
<asp:BoundField DataField="UNIT_CODE" ReadOnly ="True" HeaderText="UNIT CODE" />
<asp:BoundField DataField="UNIT_NAME" ReadOnly="True" HeaderText="UNIT NAME" />
<asp:BoundField DataField="UNIT_DO" ReadOnly="True" HeaderText="UNIT DO" />
<asp:BoundField DataField="OWNER" ReadOnly="True" HeaderText="OWNER" />
<asp:BoundField DataField="OWNER_EMAIL" ReadOnly="True" HeaderText="OWNER EMAIL" />
<asp:BoundField DataField="OWNER_PHONE" ReadOnly="True" HeaderText="OWNER PHONE" />
<asp:BoundField DataField="OWNER_MAILPOINT" ReadOnly="True" HeaderText="OWNER MAILPOINT" />
<asp:BoundField DataField="CODE_ESTABLISHED_DATE" ReadOnly="True" DataFormatString="{0:MM/dd/yyyy}" HeaderText="CODE ESTABLISHED DATE" />
<asp:BoundField DataField="LAST_REVIEW_DATE" ReadOnly="True" DataFormatString="{0:MM/dd/yyyy}" HeaderText="LAST REVIEW DATE" />
<asp:BoundField DataField="REVIEW_USERNAME" ReadOnly="True" HeaderText="REVIEW USERNAME" />
<asp:BoundField DataField="CODE_DELETED_DATE" ReadOnly="True" DataFormatString="{0:MM/dd/yyyy}" HeaderText="CODE DELETED DATE" />
<asp:BoundField DataField="DELETE_REASON" ReadOnly="True" HeaderText="DELETE REASON" />
<asp:BoundField DataField="UPDATE_USERNAME" ReadOnly="True" HeaderText="UPDATE USERNAME" />
<asp:TemplateField ShowHeader="False">
<ItemTemplate>
<asp:LinkButton ID="LinkButton2" runat="server" CausesValidation="False" CommandName="Delete"
Text='Delete'
OnClientClick="return confirm('Are you sure you want to delete this record?');"
CommandArgument='<%# bind("CODE_OWNER_ID") %>'></asp:LinkButton>
</ItemTemplate>
<ItemStyle Wrap="False" />
</asp:TemplateField>
</Columns>
<PagerStyle BackColor="#FFCC66" ForeColor="#333333" HorizontalAlign="Center" />
<SelectedRowStyle BackColor="#FFCC66" ForeColor="Navy" Font-Bold="True" />
<HeaderStyle BackColor="#990000" Font-Bold="True" HorizontalAlign="Center" ForeColor="White" />
<AlternatingRowStyle BackColor="White" />
<RowStyle BackColor="#FFFBD6" ForeColor="#333333" />
</asp:GridView>
</ContentTemplate>
<Triggers>
<asp:PostBackTrigger ControlID="btnAdd" />
</Triggers>
</asp:UpdatePanel>
<asp:SqlDataSource ID="Sqldatasource1" runat="server" ConnectionString="<%$ ConnectionStrings:Conn_Code_Owner %>"
ProviderName="<%$ ConnectionStrings:Conn_Code_Owner.ProviderName %>"
OldValuesParameterFormatString="original_{0}"
SelectCommand="SELECT * FROM CODE_OWNER"
DeleteCommand="DELETE FROM CODE_OWNER WHERE CODE_OWNER_ID = ?"
OnSelecting="_data_Selecting"
ConflictDetection="CompareAllValues" >
<DeleteParameters>
<asp:Parameter Name="Original_CODE_OWNER_ID" Type="Decimal"/>
</DeleteParameters>
</asp:SqlDataSource>
Try and wrap it w/ a Begin and End
BEGIN CODE_OWNER WHERE CODE_OWNER_ID = ? END
http://www.lazyasscoder.com/Article.aspx?id=89&title=ora-00911%3A+invalid+character+when+executing+multiple+Oracle+SQL+statements
I found an easy alternative using row-deleting event of the grid-view. I Just removed the delete parameters in the sqldatasource of asp page and then I set conflict-detection to overwrite-changes.
Sqldatasource1.DeleteCommand = "DELETE FROM code_owner WHERE code_owner_ID = :original_code_owner_ID"
Sqldatasource1.DeleteParameters.Add("original_code_owner_ID", GridView1.DataKeys(e.RowIndex).Values("code_owner_ID").ToString)
Sqldatasource1.Delete()
GridView1.DataBind()
I have a Detailsview object that is loaded with user data when a User is clicked from a gridview. The problem is, I am using a sqldatasource and I'd rather use my pre-exisiting user class which has all the built in functionality for this. I haven't been able to get this done correctly. I can't get the detailsview populated with user data without the sqldatasource, and when I try inserting or updating with my objects, it runs through the insert/update code, then fails afterwards because I don't have a InsertCommand, etc for my SQLDataSource....bottom line...can somebody help me get this working without needing the SQLDataSource?
Here's my code.
<asp:GridView runat="server" ID="gvUsers" DataKeyNames="UserID" BackColor="#eeeeee" Width="85%"
HorizontalAlign="Center"
Font-Bold="True" Font-Names="Verdana"
Font-Size="10pt" AutoGenerateColumns="False"
OnRowDataBound="GridView1_RowDataBound"
OnRowDeleting="GridView1_RowDeleting" >
<HeaderStyle BackColor="Black" ForeColor="White"
Font-Bold="True" HorizontalAlign="Center" />
<SelectedRowStyle BackColor="yellow" ForeColor="blue" />
<AlternatingRowStyle BackColor="#ffffff" />
<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:BoundField DataField="FirstName" HeaderText="First Name" />
<asp:BoundField DataField="LastName" HeaderText="Last Name" />
<asp:TemplateField HeaderText="Delete?">
<ItemTemplate>
<asp:LinkButton ID="LinkButton1"
CommandArgument='<%# Eval("UserID") %>'
CommandName="Delete" runat="server">
Delete</asp:LinkButton>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView><br /><br />
<asp:DetailsView runat="server" ID="dvUser" DataSourceID="SqlDataSource3" AutoGenerateRows="False" Width="85%"
HorizontalAlign="Center" DataKeyNames="UserID">
<Fields>
<asp:BoundField DataField="UserID" Visible="false" />
<asp:BoundField DataField="FirstName" HeaderText="First Name" />
<asp:BoundField DataField="LastName" HeaderText="Last Name" />
<asp:BoundField DataField="UserName" HeaderText="User Name" />
<asp:BoundField DataField="Password" HeaderText="Password" />
<asp:BoundField DataField="Birthdate" HeaderText="Birthdate" />
<asp:BoundField DataField="Address" HeaderText="Address" />
<asp:BoundField DataField="Apt" HeaderText="Apt" />
<asp:BoundField DataField="City" HeaderText="City" />
<asp:BoundField DataField="Province" HeaderText="Province" />
<asp:BoundField DataField="PostalCode" HeaderText="PostalCode" />
<asp:BoundField DataField="PhoneNum" HeaderText="PhoneNum" />
<asp:BoundField DataField="Email" HeaderText="Email" />
<asp:BoundField DataField="ynAdminUser" HeaderText="ynAdminUser" />
<asp:CommandField ShowDeleteButton="False" ShowEditButton="True" ShowInsertButton="True" />
</Fields>
</asp:DetailsView>
<asp:SqlDataSource ConnectionString="<%$ ConnectionStrings:ConnectionString%>" ID="SqlDataSource3"
runat="server" SelectCommand="sp_GetUser" SelectCommandType="StoredProcedure" OnInserting="OnInserting" >
<SelectParameters>
<asp:ControlParameter ControlID="gvUsers" Name="UserID" PropertyName="SelectedValue" Type="Int32" />
</SelectParameters>
</asp:SqlDataSource>
Not sure the CodeBehind is necessary, I just want to use that to call my data object code for updating, insert etc
Why not use a ObjectDataSource. This control works much like an SqlDataSource but instead of specifying an SQL query or Stored Procedure you specify the methods of your custom business object to perform your data access.
<asp:ObjectDataSource ID="ObjectDataSource" Drunat="server" DeleteMethod="Delete" InsertMethod="Insert" SelectMethod="Select" UpdateMethod="Update" TypeName="YourType">
Here's an example illustrating how to use an ObjectDataSource with a DetailsView.