Highligh a cell in a gridview - asp.net

i have a dropdownlist with two values status- 'pending' and 'completed'. while im entering a new task my status is 'pending' once i finish it off i ll change my status as 'completed'. i have displayed it in gridview. the cell which i update as 'completed' have to be highlighted and the remaining cells in the status column i.e 'pending' has to be in another color

If a serverside callback is possible in this scenario, then subscribe the OnRowDataBound-Event and look for the specific row and set the css class of a label to something different. You could use a TemplateColumn with a Label in it.
E.g.
protected void grid_RowDataBound(object sender, GridViewRowEventArgs e)
{
if(e.Row.RowType == RowType.DataRow)
{
YourObject _item = (YourObject)e.Row.DataItem;
Literal _litFromTemplate = (Literal)e.Row.FindControl("litFromTemplate");
if(_item.Equals(anotherItem)) // or check for any other condition, like _item.Foo == 123
{
_litFromTemplate.CssClass = 'highlightingMe';
}
else
{
_litFromTemplate.CssClass = 'normalcssclass';
}
}
}

Related

updating view from gridview

My query is
SELECT
deldate,
transno,
matno,
MAT_NAME,
rawpkgno,
MAX(SWITCH(deldate=? ,ORDCASES )) AS [CURRDATE],
MAX(SWITCH(deldate=? ,ORDCASES )) AS [previous_day],
MAX(SWITCH(deldate=? ,ORDCASES )) AS [Last_date]
FROM
invorder
WHERE
invorder.strno =54009
OR [invorder.deldate] IS NULL
GROUP BY
matno,
MAT_NAME,
rawpkgno,
transno,
deldate
I want to edit this from gridview. As this is view I cannot edit it from gridview. But is their any way through which previous_day, Last_date columns can be constant and I can only make changes to CURRDATE column. Kindly help me.
Hi you have to bind the row_added event on grid and there make the all the cell read only except u want editable.. check the below code..
public Form1()
{
InitializeComponent();
dataGridView1.RowsAdded += new DataGridViewRowsAddedEventHandler(dataGridView1_RowsAdded);
}
void dataGridView1_RowsAdded(object sender, DataGridViewRowsAddedEventArgs e)
{
foreach (DataGridViewCell item in dataGridView1.Rows[e.RowIndex].Cells)
{
// here i used the 5 because i want to make the 5th index cell as editable.
if (item.ColumnIndex == 5)
{
continue;
}
item.ReadOnly = true;
}
}
private void Form1_Load(object sender, EventArgs e)
{
dataGridView1.DataSource = bind_your_data_source_here;
dataGridView1.Refresh();
}
you can find the sample from here..
Download

Removing an Object from a DataSource

I am trying to remove an item which is selected in a datagrid from the domaindatasource that it uses, through a button click.
The code for the button click is:
private void medItemRemove_Click(object sender, RoutedEventArgs e)
{
if (medicineInventoryDataGrid.SelectedIndex != -1)
{
MedicineInventory M = (MedicineInventory)medicineInventoryDataGrid.SelectedItem;
MedicineInventory toRemove = (from a in ctx.MedicineInventories where (a.MedicineInventoryId == M.MedicineInventoryId) select a).Single();
ctx.MedicineInventories.Remove(toRemove);
}
}
However on clicking, I get the following error:
"The Specific Entity is not contained in the EntitySet."
Where am I going wrong?
try
MedicineInventory M = (MedicineInventory)medicineInventoryDataGrid.SelectedItem.DataItem;

show popupcontrol in rowupdating event of devexpress gridview, if a certain criteria fails

I have a Devexpress Gridview where item and it's price is displayed.
Editing is enabled.
I use rowupdating event so inorder to check if the price updated is higher than a normal value.
if so, i cancel edit by
e.Cancel = true;
ASPxGridView1.CancelEdit();
the next thing i want is to popup a aspx popupcontrol requesting a password inorder to proceed with higher amount within the rowupdating event.
the popcontrol will contain a password textbox and a button.The remaining procces will be carried out by button click function
eventhough i called popcontrol
ASPxPopupControl2.ShowOnPageLoad = true;
the pop doesn't show up......why is this so..
here is my over all code..
protected void ASPxGridView1_RowUpdating(object sender, DevExpress.Web.Data.ASPxDataUpdatingEventArgs e)
{
string msg;
double new_amt = double.Parse(e.NewValues["Amount"].ToString());//-->gets new amount
string type= e.OldValues["Type"].ToString();//-->gets the item
double refer_amt=Misc_functions.Get_Item_Amount(type,out msg);//--this function fetches the normal amount for a particular item
if (new_amt > refer_amt)
{
e.Cancel = true;
ASPxGridView1.CancelEdit();
ASPxPopupControl2.ShowOnPageLoad = true;
}
}
Basically i need a password authentication if an amount edited is a higher than a normal value.
any ideas??
This cannot be done using the server code. The best solution is to create a custom java script variable within the RowUpdating event handler and check its value in the ASPxGridView's client side EndCallback event handler. I.e.
protected void ASPxGridView1_RowUpdating(object sender, DevExpress.Web.Data.ASPxDataUpdatingEventArgs e)
{ ...
gridView.JSProperties["cpShowPopup"] = true;
...
}
EndCallback = function(s,e) {
if(typeof(s.cpShowPopup) != 'undefined') {
popup.Show();
}
}
Hope, this helps.

if i have different asp.net checkboxes in webform with different text as 450, 550, 500, 900

I have different checkboxes in vb.net webform with different text ...
checkbox1.text=100
checkbox2.text=300
checkbox3.text=550 and so on .....
i want when i check checkbox1 and checkbox2 then in textbox1 the text would be 400
means as many as checkbox i select the sun of checkboxes selected will be calculated in textbox using VB.NET ....
i m using Visual Studio 2008
If you are looking at server side code then following code should do the trick:
private int mTotal;
private void EnumerateCheckBoxes(Control control)
{
if (control is CheckBox)
{
var check = (CheckBox)control;
if (check.Checked)
{
int value;
if (int.TryParse(check.Text, out value))
{
mTotal += value;
}
}
}
else if (control.HasControls())
{
foreach(var c in control.Controls)
{
EnumerateCheckBoxes(c);
}
}
}
protected void Page_Load(Object sender, EventArgs e)
{
mTotal = 0;
EnumerateCheckBoxes(this.Form);
textbox1.Text = mTotal.ToString();
}
Although, this is in C#, it should be easy to port to VB.NET. Also few other things to consider:
This code will count radio buttons
as well as because it gets inherited
from CheckBox. If that is to be
avoided then replace if (control is
CheckBox) with if
(control.GetType() ==
typeof(CheckBox))
If you wish to consider checkboxes
from CheckBoxList then you have to
write another condition to see if
control is CheckBoxList and then
within condition, enumerate items
withing checkboxlist. Items count to
be added to total count while
selected items to be added to
checked count.
Use a hidden field and a bit of javascript to set the value, bind this event when a checkbox is checked
function UpdateValue(){
var total= 0;
$('input:checkbox:checked').each(function (i) {
val = total+ int.parse(this.value); //or html
});
$('#hiddenValField').html(total) ;
}

Determining which checkbox is checked in a checkboxlist list

I've a asp.net page which uses multi select checkboxlist(say having 10 checkboxes)....for example
I've enabled AutoPostBack for any change in checkboxlist.
Initially,out of 10, 3 are selected.
On top of this, if user checks another checkbox, how do I know which particular checkbox has been checked by the user and retrieve its value?
Thanks.
for (int i=0; i<checkboxlist1.Items.Count; i++)
{
if (checkboxlist1.Items[i].Selected)
{
}
}
protected void Page_Load(object sender, EventArgs e)
{
string name = Request.Form["__EVENTTARGET"] ?? String.Empty;
if (name.IndexOf("CheckBoxList1") != -1)
{
int last = name.LastIndexOf("$") + 1;
int index = Convert.ToInt32(name.Substring(last, name.Length - last - 1));
if (CheckBoxList1.Items[index].Selected)
{
string text = CheckBoxList1.Items[index].Text;
string value = CheckBoxList1.Items[index].Value;
}
}
}
If you want to know which last checkbox was clicked on the server side, you should enable AutoPostBack for each checkbox and capture the values accordingly. If you have the flexibility to find out the last checkbox click on the client side, then you should implement a javascript "onclick" event for each checkbox to capture the value on each checkbox and simply update the checked value in a hidden variable and pass it back to the server on postback

Resources