w3hello.com logo
Home PHP C# C++ Android Java Javascript Python IOS SQL HTML Categories
databind in gridview from dropdownlists
Try this: // Both drop down lists need a selected value or we don't do the query and bind if(!String.IsNullOrEmpty(dlName.SelectedValue) && !String.IsNullOrEmpty(dlStage.SelectedValue) { string selectedName = dlName.SelectedValue; string selectedAnnotationDate = dlStage.SelectedValue; // Use parameterized SQL instead of in-line SQL to avoid SQL Injection risks SqlCommand cmd = new SqlCommand(); cmd.Connection = YourConnectionObject; cmd.CommandText = "select [AnnotationNumber],[AnnotationBy],[AnnotationType], [BusinessUnit] as Unit,[ErrorType],[ActualAgencyError],AnnotationComments, [sgkComments],[ActualAgencyError],Cust,Name,AnnotationDate from vw_GridviewSource where Name = @p1 and AnnotationDate = @p2"; cmd.Parameters.Ad

Categories : Asp Net

The SelectedValue of DropDownLists are not set correctly
It appears that even though the SelectedValue property set belongs the DDL, it is in fact set on the ListItem, which in this case is being copied from a template ddl, and is thus a reference to the same array. I wrote this code as a solution: // Pass the template DDL to this function which will create a new separate List: private List<ListItem> GetListItems(DropDownList ddl) { return (from ListItem srcItem in ddl.Items select new ListItem(srcItem.Text, srcItem.Value)).ToList(); } // Retrieve the items from the List and assign them to the DropDownList: ddl1.Items.AddRange(GetListItems(_templateDdl).ToArray());

Categories : C#

Kendo ui grid with dropdownlists
What is probably happening is that the selection of an item in the DropDownList is changing the value on the bound data item. This causes the DataSource to fire a "change" event so hat the table knows it needs to update. The way the Kendo Grid is written, when it gets a change event from the DataSource, it recreates the table cells. I'm pretty sure the existing table cells get removed from the DOM and a new set added in its place. When this happens, the selection is getting removed. One way to preserve the selected row would be to add a function handler to the grid's "change" event, and save the uid of the selected data item. Then on the "dataBound" event, you can re-select that row. For example: var selectedUid; $("#grid").kendoGrid({ ... change: function () { select

Categories : Javascript

unable to populate 2 dropdownlists using javascript
you can do this by : window.onload = function foo() { var makeslist = document.getElementById('make'); var modelslist = document.getElementById('model'); var makestxt = "{{ makestxt }}"; var makes = makestxt.split("%"); var op = "{{ op }}"; for (i=0; makes.length; i++){ var makesvals = makes[i].split("$"); var option1 = document.createElement("option"); option1.text = makesvals[1]; option1.value = makesvals[1]; makeslist.add(option1, null); } if(op == "1"){ var modelstxt = "{{ modelstxt }}"; var models = modelstxt.split("%"); for (j=0; models.length; j++){ var modelsvals = models[j].split("$"); var option2 = document.createElement("option"); option2.text = modelsvals[1]; option2.value = modelsvals[1];

Categories : Javascript

Update SQL Database from GridView TemplateField DropDownLists
The UPDATE statement conflicted with the FOREIGN KEY constraint "FK_tbl_Job_tbl_status". The conflict occurred in database "HSE_proj", table "dbo.tbl_status", column 'Status_ID'. The statement has been terminated What this basically means is that this update would cause there to be a FOREIGN Key Violation. There are restrictions on your database that for every item in the table you are working on an item must exist in another specific table. In this case StatusID In the second part of your question: Cannot insert the value NULL into column 'Job_Department_ID', table 'HSE_proj.dbo.tbl_Job'; column does not allow nulls. UPDATE fails. The statement has been terminated. I would assume this has something to do with nullable fields. You cant have certain fields null so its evidently g

Categories : C#

Bind multiple dropdownlists to same datasource using loop
You are getting stumped because your method is only going to traverse the top-level controls since iterating over tblNetworks.Controls won't be recursive. I think that this is, in general, a very bad idea because your page will suffer from the recursion that you need to make in order to catch all the dropdowns in the page. With that said, here's a solution (in C#, sorry) that will work, regardless of the level of nesting of your dropdown lists. First, you need to create a helper method that flattens any IEnumerable so we can use LINQ: public static class ControlExtensions { public static IEnumerable<T> Flatten<T>( this IEnumerable<T> e, Func<T, IEnumerable<T>> f) { return e.SelectMany(c => f(c).Flatten(f)).Concat(e); } } And now y

Categories : Asp Net

Errror when passing values from multiple DropDownLists to controller through ViewModel
You need to change the first parameter to use SelectedSourceAccountId when creating the dropdownlist. Change @Html.DropDownListFor(viewModel => viewModel.ListOfSourceAccounts, Model.ListOfSourceAccounts, "Choose an Account") For @Html.DropDownListFor(viewModel => viewModel.SelectedSourceAccountId, Model.ListOfSourceAccounts, "Choose an Account") Same with the other Dropdownlist. Now your model should have value on it and the srcAccount and destAccount objects won't be null.

Categories : Asp Net

ASP.NET UpdatePanel Issue Maintaining Page Scroll Position With Cascading DropDownLists
What I normally do is to store the scrollPos in hidden textboxes and when the page is updated through the postback, get the values from the textboxes before rending and then scroll to that part of the screen via some javascript...

Categories : Asp Net

DataGrid edition 'EditItem' is not allowed for this view` when bound to a WPF DataGrid
I tried this and the problem is that you have initialized your Level2 collection as Hashset<>. IEditableCollectionView.EditItem() throws this error while trying to update item in Hashset<>. I initialized the collection as List<> and it was working fine. I am not sure why it is not able to update item in hashset, need to look deeper into it. But changing the Hashset<> to List<> will fix this error. Hope it helps Thanks

Categories : C#

Silverlight Datagrid scrolling, DataGrid fires RowLoading event
The RowLoading event is fired because rows are virtualized. With virtualization, rows are created (and loaded) only when they are visible on screen. So every time you scroll down or up a new row is created, loaded and the RowLoading event fired. To disable the virtualization you can try to set this property: VirtualizingStackPanel.VirtualizationMode="Standard" Be aware that this can slow down the performance of your grid if you have a lot of rows.

Categories : Database

Binding ComboBoxColumn to collection from DataGrid's ItemsSource in WPF DataGrid
MSDN: DataGridComboboxColumns says: To populate the drop-down list, first set the ItemsSource property for the ComboBox by using one of the following options: A static resource. For more information, see StaticResource Markup Extension. An x:Static code entity. For more information, see x:Static Markup Extension. An inline collection of ComboBoxItem types. So basically to just bind to data object`s collection property it`s better to use DataGridTemplateColumn: <DataGridTemplateColumn Header="Log"> <DataGridTemplateColumn.CellTemplate> <DataTemplate> <ComboBox ItemsSource="{Binding log}" /> </DataTemplate> </DataGridTemplateColumn.CellTemplate> </DataGridTemplateColumn> This type of c

Categories : Wpf

Validating A WPF Datagrid Against Data From Another Datagrid
From Microsoft official WPF course materials: ValidationRules are only to be used as simple validations (For instance Required fields, numeric formats, etc). If you need advanced / complex Business Rules validation, you should either implement IDataErrorInfo or create your own validation mechanism (that's what I did and it works like a charm)

Categories : C#

Copy selected row from datagrid at the end of datagrid
For Datagridview Databound you have to commit additional record to datasource (table) So, you have to do "INSERT INTO mytable ( fields here ... ) VALUES ( values here ..)" then to refresh your datagridview .. dt2.datasource = mytable ADDED : For your code ... try change like this insert_cmd.Parameters.AddWithValue("@Name", .item("Name")) insert_cmd.Parameters.AddWithValue("@Age", .item("Age"))

Categories : Sql Server

Master-Detail: On row click in master (DataGrid), display details (DataGrid)
If you searched online, you would have found a number of answers. For example, please take a look at the following articles: WPF Master Details MVVM Application Implementing a simple Master-Detail scenario for WPF in MVVM MVVM - Master Detail

Categories : Wpf

Copying data from a datagrid view to a new form with a new datagrid view VB
"Error 1 Reference to a non-shared member requires an object reference." As this message says: You need a instance of form2 - object of type form2created with New sub, which you created inside of BTN_Next_Click. But local variable frm_PI_01 can be used only inside of that function. With name of class form2 you can used only Shared member or functions/subs MSDN Shared members in VB My opinion if you need transfer some information/variables from form to another then in your case(when you transfer data only once when creating form) use a parameters in form constructors. Add another parameter to you form3 constructor. For example reference of your datagridview(this is may be not good practice referenced controls to another form, better create some variable with needed data and reference th

Categories : Vb.Net

How can embed datagrid in datagrid
I don't think it's possible. You can indeed manually replace a cell with the HTML of another grid (your "child" grid), but Dojo maintains its data in a store. Your store won't be "aware" of any changes you make in the DOM nodes of your grid, and inserting a DataGrid in a store isn't possible either since the DataGrid maps its columns to properties of the data objects.

Categories : Database

How to add a new row in sql from datagrid and update sql row from same datagrid?
This article on codeproject does a nice (thorough) job of demonstrating what you are asking. It also comes with some demo code. http://www.codeproject.com/Articles/37430/Datagrid-Editing-Updating-Cancel-Selecting-Rows

Categories : SQL

Binding datagrid in datagrid
You have problem with DataContext here. In RowDetailsTemplate you trying to binding to a property in main view model, but DataContext of RowDetailsTemplate is the row item. If you want to binding to property in your main view model you should use RelativeSource binding. Try this: <DataGrid ItemsSource="{Binding Path=Files}" SelectedItem="{Binding Path=DataContext.CurentFile, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=Window}}" AutoGenerateColumns="False" > ...

Categories : Wpf

sorting a datagrid with GWT
Apparently my issue was with the fact that I had a keyProvider in both classes, instead of just one. I removed it from the OpInventory class and it seems to work now. this looks like a very specific issue so I expect this question will be closed soon. but I'll leave the code there for future analysis.

Categories : Java

Vi move through DataGrid
If I understand the issue correctly - you have a focus and selection per row. You want to move focus via k/j keys and to toggle selection via x key. I like to use behaviors in these situations - it requires reference to System.Windows.Interactivity.dll from blen SDK but it also makes for a cleaner and modular code. [edit: this is a quick POC that I did. It will probably require some more null reference protection and handling of fringe/edge cases] The behavior is: using System; using System.Windows; using System.Windows.Controls; using System.Windows.Controls.Primitives; using System.Windows.Input; using System.Windows.Interactivity; namespace GridNavigationTest { public class GridNavigationBehavior : Behavior<DataGrid> { #region Overrides of Behavior ///

Categories : C#

Add, Edit DataGrid in WPF
if you have created a database or a list, u can retrieve data and print on the datagrid.. database db = new database (); //database employees emp = new employees (); //list or table in db var result1 = (from t in db.employees select t).ToList(); datagrid1.Itemssource=result1; it prints the data on datagrid

Categories : C#

Get hidden value from wpf datagrid
Rather than trying to read the value out of the Cell, why don't you just pull out the Databound item for your row? if (dgUserEnroll.SelectedItem != null) { var data = (User)dgUserEnroll.SelectedItem; var userID = data.UserId; }

Categories : C#

Cannot set DataGrid row header value
You should use HeaderText property of Columns collection instead: dataGridView_replaceTable.Columns[0].HeaderText="ROW HEADER 1"; You could also do this when you add your columns by using Caption property: public void addCol() { DataColumn column; column = new DataColumn(string colName); column.DataType = System.Type.GetType("System.String"); column.ColumnName = colName; column.Caption = "My header" // ASSIGN HEADERS HERE column.ReadOnly = false; replaceTableValues.Columns.Add(column); }

Categories : C#

How to have a DataGrid with two ButtonColumns in it?
Instead of OnSelectedIndexChanged="GradesDataGridSelectedCallback" Use OnItemCommand ="GradesDataGridSelectedCallback" And define your GradesDataGridSelectedCallback as Protected void GradesDataGridSelectedCallback(Object source , DataGridCommandEventArgs e) End Sub Checking e.CommandName would give you indication of which button is clicked.

Categories : C#

WPF MVVM DataGrid/Map
Use ObservableCollection for your data source but don't bind to that because that will bind to the default view of your collection, bind both controls to ICollectionView that you control so as you change your collection view in code both controls will update without the need to write any code to sync them... So in your case, when you filter the data, your view that is using TwoWay binding will change and since the map is bound to same view the changes in view will be immediately visible in the map as well...

Categories : Wpf

Can't refresh datagrid
If you see the old value with that type of data binding, it means you don't update the initial source, but only the temporary one (in your case t_KlantenViewSource). Calling Refresh method on the data added by FindResource cause app to reload it from pre-compiled resource, which won't change in this case. In other words, the problem is you use pre-compiled resource On the same time, you fill the dataset with actual data, but your dataset is in memory, view source - inside application file. You can try: binding ItemsSource of the entire datagrid or separate column to the TableAdapter dataset change resource compiling behaviour to Content, thus the app will reload it from external file each time you call Refresh method. ADDITION: You can find a solution for your case, just to save ti

Categories : C#

Checkbox with DataGrid WPF
For an MVVM Solution you could try this: <StackPanel> <DataGrid ItemsSource="{Binding Path=TestItems}" AutoGenerateColumns="False" Name="MyDataGrid" CanUserAddRows="False"> <DataGrid.Columns> <DataGridCheckBoxColumn Binding="{Binding IsSelected}" Width="50" > <DataGridCheckBoxColumn.HeaderTemplate> <DataTemplate x:Name="dtAllChkBx"> <CheckBox Name="cbxAll" Content="All" IsChecked="{Binding Path=DataContext.AllSelected,RelativeSource={RelativeSource AncestorType=DataGrid}}"/> </DataTemplate> </DataGridCheckBoxColumn.HeaderTemplate> </DataGridCheckBoxColumn> <DataGridTe

Categories : Wpf

Opening PDF from a DataGrid
Process.Start("filename") will open a file using the default application on that machine. In most cases, the above approach is correct. It is not dependent on a particular application or particular version of the application being pre-installed on the target machine. The advantage is loose coupling between your application and the PDF viewer. If you really need to, you can use Process.Start() to launch a particular program, many of which will accept a filename as a command line parameter, like so: Process.Start("IExplore.exe", "C:myPathmyFile.htm") (This example taken from the linked MSDN documentation) You can find a list of Adobe Reader's command line arguments here: Adobe Reader Command Line Reference Update: The above link is old (focuses on version 7). You can find version 8 d

Categories : Vb.Net

DataGrid Does not seem to allow editing
Ok, I just made an example that it is working. First I have my DataGrid definition: <asp:DataGrid ID="Grid" runat="server" DataKeyField="DatasetField1" AutoGenerateColumns="False" GridLines="None" OnCancelCommand="Grid_CancelCommand" OnEditCommand="Grid_EditCommand" OnUpdateCommand="Grid_UpdateCommand"> <Columns> <asp:BoundColumn HeaderText="Column1" DataField="DatasetField1"></asp:BoundColumn> <asp:BoundColumn HeaderText="Column2" DataField="DatasetField2"></asp:BoundColumn> <asp:EditCommandColumn EditText="Edit" CancelText="Cancel" UpdateText="Update" HeaderText="Edit"></asp:EditCommandColumn> </Columns> Second I must bind my data grid: public BindData() { .... Grid.DataSource = [MyDataSet With DatasetFi

Categories : C#

Triggers in datagrid
I'm not very experienced with DataGrid, so this might not be the best option, but I think you can achieve what you're after by styling the Row, rather than the individual Columns: <DataGrid <!-- Your settings here -->> <!-- Your column definitions here --> <DataGrid.RowStyle> <Style TargetType="DataGridRow"> <Style.Triggers> <DataTrigger Binding="{Binding Path=Errorcode}" Value="0"> <Setter Property="Background" Value="LightGreen" /> <!-- Other Setters --> </DataTrigger> <DataTrigger Binding="{Binding Path=Filename}" Value="File not created"> <

Categories : C#

WPF DataGrid and ITypedList
ICustomTypeDescriptor implementation is required for Row objects. http://social.msdn.microsoft.com/Forums/en-US/wpf/thread/177aef94-62c5-438d-a4a9-8834390559ad

Categories : C#

Create DataGrid in WPF at runtime
Why not skip doing all that stuff in cs code? You'll start pinning yourself in the corner and WILL hit the wall when the datagrid will need more complex templates, data triggers, custom styles, animations, etc... Besides, it will make it easier not only on the next person, but you as well. When you have to add/fix something in the beast you create in .cs code 3-6 months down the road, it might take you quite a while to understand what is going on :) Instead, do all your work in xaml, Create a UserControl, put this datagrid in it, Pass the DataContext from various instances of the UserControl down to it's DataGrid.

Categories : Wpf

DataGrid with multiple headers
I have managed to create the following: If I understand correctly, in this case, you must use a nested DataGrid. This effect can be achieved by DataGridTemplateColumn.CellTemplate -> your DataTemplate. Also, the pattern should be "normal" TextBlock, so it shows some value when nested DataGrid hidden. Checks will be carried out using DataTrigger in DataTemplate. XAML code: <DataGrid Name="SimpleDataGrid" AutoGenerateColumns="False" RowHeaderWidth="0" CanUserAddRows="False" CanUserResizeColumns="False" CanUserResizeRows="False" Loaded="SimpleDataGrid_Loaded"> <DataGrid.Columns> <DataGridTemplateColumn Width="1.5*" Header="HeaderWithDataGrid" IsReadOnly="False"> <DataGridTemplateColumn.CellTemplate> &l

Categories : Wpf

how can be add WPF DataGrid in Windows Form?
Have a look at this thread. It explains the two controls (Datagrid in WPF and DatagridView in Winforms). It behaves more or less the same, but has a different framework in the background.

Categories : Wpf

Bizarre WPF DataGrid issue
i think this is change in behaviour occurs because on one machine there is .NET 4.5 installed and on the other .NET 4.0 The behaviour of the WPF DataGrid seems to be a little different. In .NET 4, the DataGrid has some issues when binding to anonymous types. Solutions: Use .net 4.5 on all computers Define the DataGrid Columns manually and set AutogenerateColumns to false Use normal classes instead of anonymous types replace select new { Symbol = "XXX", Quantity = 6000, ... }; with select new Stock { Symbol = "XXX", Quantity = 6000, ... };

Categories : C#

Link Combobox and datagrid
If you are looking to find a 'selection changed' event for a DataGrid, please take a look at the WPF datagrid selected row clicked event? post here at StackOverflow. In short, you can attach a handler to the DataGridRow.Selected event: <DataGrid ... > <DataGrid.ItemContainerStyle> <Style TargetType="DataGridRow"> <EventSetter Event="MouseDoubleClick" Handler="Row_DoubleClick"/> </Style> </DataGrid.ItemContainerStyle> ... </DataGrid> From the linked post.

Categories : C#

Extract DataSet from DataGrid
As @HighCore has mentioned, in WPF, we work with data and Binding. We would normally set the ItemsSource property of the DataGrid to our data object like this: dataGrid.ItemsSource = ds.Tables[0]; Therefore, we would normally retrieve the values simply by looking in the ds variable.

Categories : C#

DataGrid get Cell Contents
Instead of ItemCreated Event, use the ItemDataBound evet. ItemCreated: The row is created and and itemtemplate controls are also created. ItemDataBound: The data is now bound to the control. Example: Markup <asp:DataGrid id="grdTeset" OnItemDataBound="grdTeset_ItemDataBound" runat="server" AutoGenerateColumns="false"> <Columns> <asp:BoundColumn DataField="Column1" /> <asp:BoundColumn DataField="Column2" /> </Columns> </asp:DataGrid> Example Code Behind: public class Data { public string Column1 {get;set;} public string Column2 {get;set;} } public partial class _Default : System.Web.UI.Page { public List<Data> data = new List<Data>(); protected void Page_Load(object sender, EventArgs e) {

Categories : C#

FormatString on WPF-DataGrid has no effect
Here is my solution: I can't simple use FormatString, without binding a datetime. So i wrote an IValueconverter: public class StringDateTimeValueConverter : IValueConverter { public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture) { DateTime cOutDateTime = DateTime.Now; if (DateTime.TryParse(value.ToString(), out cOutDateTime)) { return cOutDateTime; } else { return DependencyProperty.UnsetValue; } } public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture) { return value.ToString(); } }

Categories : C#

Binding an ObservableCollection to a DataGrid
Set the properties you want databound to public public string FileName { get { return fileName; } set { fileName = value; OnPropertyChanged("FileName"); } } public string Path { get; set; } public string Extension { get; set; }

Categories : C#



© Copyright 2017 w3hello.com Publishing Limited. All rights reserved.