Usage of DataKeyNames in an ASP.NET GridView? - asp.net

In which cases should I use a GridView's property DataKeyNames?
Why are multiple columns/fields allowed here?

Gets or sets an array that contains the names of the primary key fields for the items displayed in a GridView control.
GridView.DataKeyNames Property
GridView.DataKeys Property

It keeps the primary key fields or id field of data table, which gridview shows.
According to MSDN
Gets or sets an array that contains
the names of the primary key fields
for the items displayed in a GridView
control.

Related

How fill a dbcombo with all the records of a specific field visual basic 6

I need to fill the full dbcombo with all the records the a specific field in visual basic 6. I joined that dbcombo with a data control and I specified the property called datafield, but the dbcombo show only a record
Can something help me please?
I want the contents of the combobox to show Select * from students" in sql.
I have the datasource of the controldata point to "students.mdb"
You are confusing the different properties in the DBCombo box. There are four properties you need to be aware of:
DataSource
DataField
RowSource
ListField
To get the list you want, you need to set the RowSource to the Data Control, and the ListField to the field you want, in your case Students.
DataSource and DataField you only need if you are going to be updating the underlying database. DataSource is again the Data Control, and DataField is which field you want to update--it doesn't need to be the same field as the ListField.

Set default value of dropdownlist based on datasource

I have a webform that uses a dropdownlist to populate a gridview. The dropdown list is bound to a datasource. I would like to have the default value of the dropdown list be a value in the listing. I have a series of 5 values, one of which is actually a blank. The default value I am looking for would be index 2 or the value "Agency Error"
Here is the query I have for the datasource:
SELECT DISTINCT [AnnoType] FROM [AnnoType]
Is there a way to do this?
I am just trying to eliminate one of maybe 50 clicks the user needs to do in the process.
Use SelectedIndex property
dropdownlist.SelectedIndex = 2;
or SelectedValue property
dropdownlist.SelectedValue = dropdownlist.Items.FindByText("Agency Error").Value;

How to persist an ASP:Table with TextBoxes inside cells?

I have an ASP.Table whose cells are containing textboxes filled by the user.
When he clicks on a button, I want to store textboxes content into a database but in the onclick event, the table is empty. How can I persist the whole table, and especially the textboxes data ?
Create a name value collection corresponding to the columns and rows of the table. Store each cell value as a part of the name value collection in the DB with the name in the form of r1c1, r1c2, etc.

GridView not updating when data comes from multiple tables

I have a GridView control that gets data from two tables, the first one contains a primary key, a name (string) and a foreign key to the second table, The second table contains a primary key "referenced by the foreign key mentioned" and a name (string), i was able to display the id, name (first table) and the name (second table) using an inner join but i can't update the data in the tables using the GridView (when pressing update nothing happens at all, or no change occurs).
From what i understand of your question what you have is a situation that you must a apply a nested gridview.
A gridview shows the content of a table (datatable or a collection).
If you want to show other collection that is inside each row of your primary gridview, you will need
to build a second Gridview or listview or repeater to show that information.
with the primary griview you can use the OnItemDataBound to assign the datasource of the nested gridview or what you choose to show that information based in primary key of the row.
Don't bother i found a solution to the problem on Microsoft website, i am sorry i didn't make my question pretty clear and here is a link to what i was looking for: Editing with Template Fields
Maybe after clicking Update you need to call your read method again to refresh your gridview.
something Like:
UpdateMethod()
{
//YOUR UPDATE STUFF
//REBIND DATA WITH UPDATED RECORDS
RefreshMethod(); //YOUR BINDING METHOD TO DATAGRID STUFF
}

how to set selected elements in DevExpress' CheckedComboBoxEdit

I'm a newbie for DevExpress controls. I have a DevExpress checkedComboBoxEdit control that is populated by data from SQL Server using Linq. Populating the checkedComboBox elements worked fine but I couldn't figure out how to set the selected elements.
The DB table contains three fields
id (Value Member),
Role (Display Member)
Applies (contains 0 for unselected and 1 for selected)
I want to select the checkbox elements based on the Applies field. How can I do this? Or is there a better way of doing this by modifying the database table? Or is there a CheckedComboBox property to do this?
Thanks
You should find all you need in the DevExpress online doumentation. In particular:
To initialize the check items' values and display text with values of
these fields, assign the names of the fields to the
RepositoryItemCheckedComboBoxEdit.ValueMember and
RepositoryItemCheckedComboBoxEdit.DisplayMember properties.
So in your case, you should assign 'Role' to the DisplayMember property and 'Applies' to the ValueMember property (rather than 'id').
To Unchecked all items in CheckedComboBoxEdit
For i = 0 To CheckedComboBoxEdit1.Properties.Items.Count - 1
clUSER_ID.CheckedComboBoxEdit1.Items.Item(i).CheckState =
CheckState.Unchecked
Next

Resources