Work on Asp.Net C# VS08.
I have a GridView which was binded to an ObjectDataSource with edit command link capabilities enabled.
Whenever the user go on edit a row and changes a given cell, I'd like to change another cell value programatically change a cell value (according to the new cell value typed by the user).
So, is it possible to change cell values programatically on edit mode?
I took a gridview with Five columns. In first column i have edit buttons. In second column i have name and in third i have age,StartTime,EndTime.On my name cell i used PopupControlExtender,When user click on Name Cell they see a gridview popup containing Name And Age from there they chose appropriate name.After chose the name i want Age will be set Automatically on My Age cell.
Where to Write,How to write methods.On PopupControlExtender popup grid i can select and set value on name cell using the bellow code
protected void GridView2_SelectedIndexChanged(object sender, EventArgs e)
{
string b = ((Label)GridView2.SelectedRow.FindControl("lblCOM_NAME")).Text;
AjaxControlToolkit.PopupControlExtender.GetProxyForCurrentPopup( this.Page).Commit(b);
}
i want user click the name cell value after this age will be set automatically on Age cell from popup grid.How to set the Value?
Use a template column and then
row[0].Cell[0].FindControl("txtTextBox")
with the correct cast.
I dont have VS on this machine but that should be about right.
Related
I'd like to show a listview in a C# application where every row represents a product so the property "view" is set on "detail". One column (the last one) should be a checkbox because it represents if the product is discountinued.
With the checkboxes property set to true, a checkbox appear in the first column so it doesn't work for my application.
How can add the checkbox to the last column? Thank you
The Checkboxes are always associated with the first Column. However you change re-order the display of the Columns.
All you need to do it go to the Columns designer and set the 1st colum's DisplayIndex to the last column's index.
Or do it in code:
listView1.Columns[0].DisplayIndex = listView1.Columns.Count - 1;
listView1.Invalidate();
Note the Invalidate which is necessary to enforce the display of the new layout..
I have DataGridView with about 5 columns and the last column is a DataGridViewLinkColumn type. So the requirement here is that I should be able to select any row I want and when I do that, all the columns should be selected except the last column in that selected row. As the last column contains a hyperlinked text and there are some functions written which are intended to run.
Currently I have set the selection mode to FullRowSelect.
To achieve the requirement I have tried to set the mode to CellSelect and in the CellContentClick I was setting 'Selected' property for the specific columns of a selected row. But the selection wasn't happening properly. It would disappear as soon as I click. Also I tried to put the same logic in CellMouseUp, but it did't work either.
Kindly suggest me ways or workarounds for achieving the requirement.
Many Thanks!
First set the SelectionMode to CellSelect. Then code the SelectionChanged event:
private void dataGridView1_SelectionChanged(object sender, EventArgs e)
{
foreach (DataGridViewCell c in dataGridView1.CurrentRow.Cells)
c.Selected = c.ColumnIndex != 4;
}
Note that this makes no provisions for deselecting a row!
I have a data grid view with combo box column in it, i have bind that column to datatable like this:
((grdItems.Columns[1]) as DataGridViewComboBoxColumn).DataSource = dt;
((grdItems.Columns[1]) as DataGridViewComboBoxColumn).DisplayMember = "LocationName";
((grdItems.Columns[1]) as DataGridViewComboBoxColumn).ValueMember = "Id";
now i can get the selected value like this:
var value = grdItems.Rows[0][1].Value;
but the issue is, when i manually add the rows in the gridview (without binding the grid), i cant get the value of the combobox cell.
i am adding rows like this:
grdItems.Rows.Add(1, 1, "Some Value");
when i use
var value = grdItems.Rows[0][1].Value;
this method to get the value, i returns me the text of the cell not the value i.e 1 in this case.
How can i solve this issue? since i want the value of the cell in case of adding rows manually, as well as data-bind rows.
Am assuming that by manually adding rows you mean from the UI , so one way to get the value of the newly added row is to use an event handler for the events raised when you add an row. You may use one of the following
1) RowsAdded https://msdn.microsoft.com/en-us/library/system.windows.forms.datagridview.rowsadded(v=vs.110).aspx 2) RowPrePaint - https://msdn.microsoft.com/en-us/library/system.windows.forms.datagridview.rowprepaint(v=vs.110).aspx - not used this much but is also an option
this.myGridView.RowsAdded += new DataGridViewRowsAddedEventHandler(myGridView_RowsAdded);
private void myGridView_RowsAdded(object sender, DataGridViewRowsAddedEventArgs e)
{
var newRow = this.myGridView.Rows[e.RowIndex];
}
Edit: Based on the actual requirement stated in the comments - actual requirement being retrieving the newly added row's cell value (Id) corresponding to the combox box column on button save clicked event
Assuming you have bound the combo box to a data source itself , meaning, your
combobox.DataSource=someList
so what you can do is write a linq query
someList.Where( v=>v.Text.Equals("row.Cells[1].Value")).FirstOrDefault().Id
here i am going to update multiple values at a time by using single button click
On clicking update button for gridview it is showing multiples values for each and every column
After refreshing the page it is showing normal data
For example if i am inserting 1 in 1st column, 2 in 2nd column after updating gridview it is showing 1,1 2,2 like that
Because your gridview has autogeneratecolumn = true. change to false.
Or if you want custom header name do this steps:
in gridview property (Design part) click edit columns -> your boundfield -> under its property, you can see the "DataField", set your field name of your database. You can see now the data of your records from your database. also you can set header name.
how to set the value of datagridview textbox i.e each row with textbox should contain some value (e.g in my case 0.0) and also if user doesn't enter any value it should set value 0.0.
I tried to use cellleave event of datagridview but its not helping...
what i am really want to do is set the certain default value in cell if user does not give any input. Once user lefts the current cell it should show the default value.
now this is my code
private void dgvSellbox_CellLeave(object sender, DataGridViewCellEventArgs e)
{
if (dgvSellbox.CurrentCell.Value == null )
{
dgvSellbox.CurrentCell.Value = 0.0;
}
}
You can set defaults for the a column by the designer
On you DataGridView -> Click Edit Columns
Now you should see the Edit Columsn Dialog
Select the Column you want to set default
Now at the right side you should the property called DataGridViewCellStyle
Please click on DataGridViewCellStyle this will show Cell Style Builder Dialog
Under Data -> Set the NullValue property to 0.0
Keep on clicking Ok Buttons till you are back to the DataGridView
Hope this helps...