We have several terminals throughout the plant that employees will be using to submit part requests through our supply/warehouse department.
This Supply Warehouse will have a terminal displaying an "orders" website, showing a list of part numbers and the employees who are waiting for them.
Everything works now, but I only know how to get the data to refresh by coding in a <META REFRESH> tag, which doesn't really work well and causes a lot of other information on the form to get lost in the process.
How would I go about telling the webpage to "listen" for changes or simply update the GridView once a minute or so?
I've seen websites do it. This site pops up a note as soon as someone responds, finance sites pop up the latest stock quotes every few seconds, etc. I don't know what the technology is called or how I would use it.
Do I write some code in the codebehind?
protected void Page_Load(object sender, EventArgs e) {
// ???
}
Here is the basics of what I have.
<asp:SqlDataSource ID="productionDataSource2" runat="server" ConnectionString="<%$ ConnectionStrings:CPWEB_PRODUCTION %>" SelectCommand="SELECT [RequestID], [Employee], [DateStamp], [Line], [PartNo], [Workorder], [Qty], [MTF], [Status] FROM [vwRequestsEx] WHERE ([Status] = #Status)"><SelectParameters>
<asp:ControlParameter ControlID="ddlSelector" Name="Status" PropertyName="SelectedValue" Type="String" />
</SelectParameters>
</asp:SqlDataSource>
<asp:GridView ID="GridView1" runat="server" AllowPaging="True" AllowSorting="True" AutoGenerateColumns="False" AutoGenerateSelectButton="True" CellPadding="1" DataSourceID="productionDataSource2" EmptyDataText="No Records to Display" Font-Size="Small" ForeColor="#333333" OnSelectedIndexChanged="GridViewRow_Selected" ShowHeaderWhenEmpty="True" HorizontalAlign="Left" RowHeaderColumn="RequestID" Width="95%">
<Columns>
<asp:BoundField DataField="RequestID" HeaderText="RequestID" SortExpression="RequestID" />
<asp:BoundField DataField="Employee" HeaderText="Employee" SortExpression="Employee" />
<asp:BoundField DataField="DateStamp" HeaderText="DateStamp" SortExpression="DateStamp" />
<asp:BoundField DataField="Line" HeaderText="Line" SortExpression="Line" />
<asp:BoundField DataField="PartNo" HeaderText="PartNo" SortExpression="PartNo" />
<asp:BoundField DataField="Workorder" HeaderText="Workorder" SortExpression="Workorder" />
<asp:BoundField DataField="Qty" HeaderText="Qty" SortExpression="Qty" />
<asp:BoundField DataField="MTF" HeaderText="MTF" SortExpression="MTF" />
<asp:BoundField DataField="Status" HeaderText="Status" SortExpression="Status" />
</Columns>
</asp:GridView>
I'm getting a lot of downvotes lately. Downvoters: That's OK, but kindly let me know why so I'll understand what is wrong.
There is an easy solution using UpdatePanels and a Timer in the answer to this question: gridview that is updated frequently
You should look at using SignalR to achieve this.
Related
I have created a GridView in Visual Studio 2010.
The information displayed in the GridView is controlled by a dropdown list.
Can I add a "Show all" option to the dropdown list so that the GridView shows all the data?
This is what I have so far...
Dropdown list
<asp:DropDownList ID="DropDownList2" runat="server"
DataSourceID="dorpDownList2" DataTextField="Type" DataValueField="Type" AppendDataBoundItems="true"
AutoPostBack="True">
<asp:ListItem Value="0" Text="Select a type"></asp:ListItem>
</asp:DropDownList>
GridView code
<asp:GridView ID="GridView1" runat="server" AllowSorting="True"
AutoGenerateColumns="False" DataSourceID="SqlDataSource1" ShowHeaderWhenEmpty="True" emptydatatext="No data was found.">
<Columns>
<asp:BoundField DataField="OrgName" HeaderText="Organisation"
SortExpression="OrgName" />
<asp:BoundField DataField="ProjectTitle" HeaderText="Project title"
SortExpression="ProjectTitle" />
<asp:BoundField DataField="Type" HeaderText="Type"
SortExpression="Type" />
<asp:BoundField DataField="Amount"
HeaderText="Amount" SortExpression="Amount"
DataFormatString="{0:c}" />
<asp:HyperLinkField DataNavigateUrlFields="OrgName"
DataNavigateUrlFormatString="orgDetails.aspx?OrgName={0}"
HeaderText="Details" Text="Organisation details" />
</Columns>
</asp:GridView>
SqlDataSource1
<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="<%$ ConnectionStrings:MyConnectionString %>"
SelectCommand="SELECT [OrgName], [ProjectTitle], [Type], [Amount] FROM [tabRequest] WHERE [Type] = #Type">
</asp:SqlDataSource>
I can obviously add "Show all" to the drop down list using asp:ListItem but how do I add the functionality to make that actually show all the results?
Any help would be greatly appreciated.
Thanks,
James
The easiest way is via the Configure Data Source context menu. You already have a parameter, as you move through the configuration process you come to a dialog called Define Parameters. You should see "Type" listed in the Parameters list. Select it and change the Parameter source to "Control" and when prompted specify the DDL.
The trick is that you need to effectively remove the condition on your select where clause when Type is 0. This is easily done with an IF statement.
I'm trying to allow for editing of the items in a GridView (the DataSource is a database connection). Every example I find has complicated examples implemented within. I'd like to know what the simplest change(s) I need to do are in order to allow for editing of items in the GridView.
In other words, how can I modify the following to allow for editing?
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" DataSourceID="SqlDataSourceWS">
<Columns>
<asp:CommandField ShowSelectButton="True" />
<asp:BoundField DataField="id" HeaderText="id" InsertVisible="False" ReadOnly="True" SortExpression="id" />
<asp:BoundField DataField="NAME" HeaderText="NAME" SortExpression="NAME" />
<asp:BoundField DataField="ACCESS_TO" HeaderText="ACCESS_TO" SortExpression="ACCESS_TO" />
</Columns>
</asp:GridView>
Obviously I'd need to add code as well, but I'm just not sure how to start with this.
EDIT: I thought I'd specified, but I didn't - it's an SQLDataSource.
There are several thing you need to do to enable editing
Assuming that your data source is an SQLDataSource
1) Add a command field to your girdview columns
<asp:CommandField ButtonType="Button" EditText="Edit" ShowEditButton="true"/>
2) Add an update command to your data source
<asp:SqlDataSource ID="SqlDataSourceWS" runat="server"
ConnectionString="<%$ Connection String %>"
SelectCommand=" SELECT COMMAND HERE "
UpdateCommand=" UPDATE COMMAND HERE ">
<UpdateParameters>
<asp:Parameter Name="" />
<asp:Parameter Name="" />
</UpdateParameters>
</asp:SqlDataSource>
For more information on the command field and how to use it you can look at the Microsoft Developer Network Documentation
EDIT
Here is a very simple example of a SQLDatasource that shows how you may update an item
<asp:SqlDataSource ID="sqlMeetings" runat="server"
ConnectionString="<%$ connection %>"
SelectCommand="SELECT [meetingid]
,[groupname]
,[meetingtime]
,[meetingdate]
FROM [DCMS].[dbo].[tbl_meetings] "
UpdateCommand="UPDATE tbl_meetings
SET meetingdate = #meetingdate, meetingtime = #meetingtime
WHERE meetingid = #meetingid">
<UpdateParameters>
<asp:Parameter Name="meetingdate" />
<asp:Parameter Name="meetingtime" />
</UpdateParameters>
</asp:SqlDataSource>
From the example above you can see that I am selecting 3 fields from the data base but only allowing for two to be updated (meetingdate and meetingtime).
To edit the records, the GridView must enter EditMode. The grid changes modes according to the commands it receives, in this case "edit". See the remarks on the gridview page, 'Data Operations' section, for more info.
There are basically three ways to fire the command and enter edit mode on the grid:
Use the AutoGenerateEditButton property on the grid
Use a CommandField with ShowEditButton like the other answer stated
Use a custom TemplateField with a LinkButton inside like this:
<Columns>
...
<asp:TemplateField>
<ItemTemplate>
<asp:LinkButton runat="server" Text="Edit" CommandName="Edit" />
</ItemTemplate>
<EditItemTemplate>
<asp:LinkButton runat="server" Text="Update" CommandName="Update" />
<asp:LinkButton runat="server" Text="Cancel" CommandName="Cancel" />
</EditItemTemplate>
</asp:TemplateField>
...
</Columns>
After that, it will depend on which DataSource control you are using. With an EntityDataSource, for instance, all you need to do is set EnableUpdate="true"
I have a web app I'm trying to write that will get the percentages of supplies left in a printer. and display that in a friendly 1-100 percent number. to get that number i must multiply what is left by 100 then divide that by the total possible.
I have not been able to take the data that is coming from a sql server table and modify it before it is rendered into the data gridview. Any help would be appreciated.
I've already tried in the code behind to convert it to integer with no luck. Here is my code.
ASPX
<asp:GridView ID="GridView2" runat="server" AllowSorting="True"
AutoGenerateColumns="False" BackColor="#DEBA84" BorderColor="#DEBA84"
BorderStyle="None" BorderWidth="1px" CellPadding="3" CellSpacing="2" OnRowDataBound = "changeToPercent"
DataSourceID="SqlDataSource1" EnableModelValidation="True">
<Columns>
<asp:BoundField DataField="p_ipaddress" HeaderText="p_ipaddress"
SortExpression="p_ipaddress" />
<asp:BoundField DataField="s_prtmarkerssuppliesdescription"
HeaderText="s_prtmarkerssuppliesdescription"
SortExpression="s_prtmarkerssuppliesdescription" />
<asp:BoundField DataField="s_prtMarkersSuppliesLevel"
HeaderText="s_prtMarkersSuppliesLevel"
SortExpression="s_prtMarkersSuppliesLevel" />
</Columns>
<FooterStyle BackColor="#F7DFB5" ForeColor="#8C4510" />
<HeaderStyle BackColor="#A55129" Font-Bold="True" ForeColor="White" />
<PagerStyle ForeColor="#8C4510" HorizontalAlign="Center" />
<RowStyle BackColor="#FFF7E7" ForeColor="#8C4510" />
<SelectedRowStyle BackColor="#738A9C" Font-Bold="True" ForeColor="White" />
</asp:GridView>
<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="<%$ ConnectionStrings:XrxDBCWWConnectionString %>"
SelectCommand="usp_SUPPLYPERCENTAGE" SelectCommandType="StoredProcedure"
CancelSelectOnNullParameter="False">
<SelectParameters>
<asp:ControlParameter ControlID="percentBox" DefaultValue="10"
Name="PCT_REQUESTED" PropertyName="Text" Type="Int32" />
<asp:Parameter DefaultValue="" Name="PRINTER_ID" Type="String" />
</SelectParameters>
</asp:SqlDataSource>
I have no CS Code to use because everything i have tried has failed miserably
Try wiring up the GridView's RowDataBound event, where you would have access to the Row data, and can update them before it gets bound to the grid view.
http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.gridview.rowdatabound.aspx
void GridView2_RowDataBound(Object sender, GridViewRowEventArgs e)
{
if(e.Row.RowType == DataControlRowType.DataRow)
{
// Display the company name in italics.
e.Row.Cells[1].Text = "<i>" + e.Row.Cells[1].Text + "</i>";
}
}
Sorry about the premature post. I had given up entirely editing my code so instead i went to the source and looked at the stored procedure to see if i could make it work there. Just so happens that you can do Mathmatical function INSIDE your SELECT statement.
This is what i added in the select.
SELECT ((s_prtMarkersSuppliesLevel *100) / s.s_prtMarkersSuppliesMaxCapacity) as s_prtMarkersSuppliesLevel
Sample
<asp:GridView ID="data_basic_addresses" runat="server" AllowPaging="False" BorderWidth="0" AllowSorting="True" AutoGenerateColumns="False" DataKeyNames="AddressId" HorizontalAlign="Center"
DataSourceID="LinqAddressDS" PageSize="20" CssClass="GridViewClass">
<Columns>
<asp:BoundField DataField="AddressId" HeaderText="AddressId" SortExpression="AddressId" ReadOnly="True"/>
<asp:BoundField DataField="Address" HeaderText="Street" SortExpression="Address" />
<asp:BoundField DataField="City" HeaderText="City" SortExpression="City" />
<asp:BoundField DataField="State" HeaderText="State" SortExpression="State" />
<asp:BoundField DataField="Zip" HeaderText="Zip" SortExpression="Zip" />
<asp:CommandField HeaderText="Options" ShowDeleteButton="True" ShowEditButton="True" />
</Columns>
</asp:GridView>
<asp:LinqDataSource ID="LinqAddressDS" runat="server" OnContextCreating="LinqDS_ContextCreating" Where="AcctNo == #AcctNo"
ContextTypeName="MyProject.Models.DB_DataDataContext" EnableDelete="True" EnableInsert="True"
EnableUpdate="True" TableName="Tbl_Addresses" OrderBy="AddressId">
<WhereParameters>
<asp:QueryStringParameter DefaultValue="1" Name="AcctNo" QueryStringField="AcctNo" Type="Int32" />
</WhereParameters>
</asp:LinqDataSource>
I set the WhereParamater value in the page_load method
Every time the update link is pressed after data is changed I receive an error stating "A critical error has occurred. Exception has been thrown by the target of an invocation." or "Cannot access a disposed object"
When the grid view is reload fresh, the data is updated. Nothing I do seems to make a difference. Does anyone have any ideas on why?
Thanks in advance!
Found a fix for the problem
I was trying to pass my own instance of the model connection to be used in a LinqDS_ContextCreating method. This worked for all functionality except the Update command. I went in and updated the models default connection string in the model.designer.cs file and now the update works.
I have an issue working with the telerik radgrid control. I am trying to use javascript to access a textbox when the grid is in edit mode.
My code looks like the following:
<telerik:RadGrid ID="RadGrid1" GridLines="None" runat="server" AllowAutomaticDeletes="True"
AllowSorting="False" AllowAutomaticInserts="True" PageSize="10" AllowAutomaticUpdates="True"
OnItemDataBound="RadGrid1_ItemDataBound" AllowMultiRowEdit="False" AllowPaging="False"
DataSourceID="DataSource1" OnItemUpdated="RadGrid1_ItemUpdated" AllowFilteringByColumn="False"
OnItemDeleted="RadGrid1_ItemDeleted" OnItemInserted="RadGrid1_ItemInserted" AutoGenerateColumns="false"
OnDataBound="RadGrid1_DataBound">
<PagerStyle Mode="NextPrevAndNumeric" />
<MasterTableView Width="100%" CommandItemDisplay="TopAndBottom" DataKeyNames="Id"
DataSourceID="DataSource1" HorizontalAlign="NotSet" EditMode="EditForms">
<Columns>
<telerik:GridEditCommandColumn ButtonType="ImageButton" UniqueName="EditCommandColumn">
<ItemStyle CssClass="MyImageButton" />
</telerik:GridEditCommandColumn>
<telerik:GridButtonColumn ConfirmText="Delete this product?" ConfirmDialogType="RadWindow"
ConfirmTitle="Delete" ButtonType="ImageButton" CommandName="Delete" Text="Delete"
UniqueName="DeleteColumn">
<ItemStyle HorizontalAlign="Center" CssClass="MyImageButton" />
</telerik:GridButtonColumn>
<telerik:GridBoundColumn DataField="Id" HeaderText="Id" Display="false" ReadOnly="true" />
<telerik:GridBoundColumn DataField="Manufacturer" HeaderText="Manufacturer" />
<telerik:GridBoundColumn DataField="Description" HeaderText="Description" />
<telerik:GridBoundColumn DataField="Configuration" HeaderText="Configuration" />
<telerik:GridDropDownColumn DataField="TypeId" HeaderText="Type" UniqueName="PartsType"
DataSourceID="PartsTypeDataSource" ListTextField="Name" ListValueField="Id" />
What I am after is that, during edit mode, when the user selects a certain value from the dropdown list 'PartsType', one of the other fields - eg 'Manufacturer' will be shown/hide.
I could get the dropdown value (in javascript) by attaching a javascript function to the dropdownlist:
function PartsTypeIndexChanged(sender, args) {
var selectedValue = args.get_item()._text;
}
I just dont know which method to use to get the 'Manufacturer' field, so I can show/hide it.
Could anyone please help?
Many thanks.
A possible approach could be to use RadControls client-side static API
$telerik.findElement(gridDOMElement, "Manufacturer");
This will help you access the column editor - I suppose it is ASP.NET TextBox rendered as input. For numeric or date columns the editor will probably be Telerik client component so you have to use findControl instead of findElement.
More info here:
http://www.telerik.com/help/aspnet-ajax/telerik-static-client-library.html
Good luck
Please check below link.
http://www.telerik.com/community/forums/aspnet-ajax/grid/set-controls-attribute-like-enable-disable-on-insert-edit-mode-using-jquery.aspx