My dataset contains null values and - by default - null values come first.
When sorting the data, how do I get null values last?
Handle the OnColumnSort event for your ASPxGridView as below:
protected void myGrid_CustomColumnSort(object sender, CustomColumnSortEventArgs e)
{
if (e.Column == null)
return;
if (!e.Column.FieldName.ToString().Equals("myColumnFieldName"))
return;
if (e.Value1 == DBNull.Value || e.Value1 == null)
e.Result = 1;
else
if (e.Value2 == DBNull.Value || e.Value2 == null)
e.Result = -1;
else
e.Result = Comparer.Default.Compare(e.Value1, e.Value2);
e.Handled = true;
}
And set the SortMode attribute for yout column as:
<Settings SortMode="Custom" />
Related
When I pass the string value to the dropdown, it is not getting selected. I am not sure why?
I've tried passing the value eg:ddlInitialIncidentType.Items.FindByValue("1").Selected = true; directly which works fine.
protected void btnIncTypeSave_Click(object sender, EventArgs e) {
string value;
if (rbIncTypeY.Checked == true) {
//getting the value number from the Label
value = label.Text;
ddlInitialIncidentType.ClearSelection();
//here I want to select the dropdown with the value number
ddlInitialIncidentType.Items.FindByValue(value).Selected = true;
}
}
Note: I am assigning the value to the label in the below method
function prioritySelection(sender) {
var e = document.getElementById(sender.id);
e = e.value;
if (e == 2 || e == 4 || e == 1 || e == 3)
{
$('#<%=lblInitialIncidentTypeCurrent.ClientID%>').html(e); $find("ContentPlaceHolder1_ContentPlaceHolder2_ModalPopupIncidentTypeChange").show();
}
protected void btnIncTypeSave_Click(object sender,EventArgs e)
{ string value; if (rbIncTypeY.Checked==true) {
value=label.Text; // did you check here that value gets value or not?} }
In your javascript code you have used the ID of the Label control as lblInitialIncidentTypeCurrent where as in your server side code your are using some other Label control.
Replace this
value = label.Text;
with
value = lblInitialIncidentTypeCurrent.Text;
There was some problem by using the Label to store the value.
But by using HiddenField it is solved.
Thanks all for the answers provided.
below is the code for it,
//aspx.cs
<asp:HiddenField ID="hdtest" runat="server" />
protected void btnIncTypeSave_Click(object sender, EventArgs e)
{
string value;
if (rbIncTypeY.Checked ==true)
{
value = hdnIncType.Value;
ddlInitialIncidentType.ClearSelection();
ddlInitialIncidentType.Items.FindByValue(value).Selected = true;
ModalPopupIncidentTypeChange.Hide();
rbIncTypeY.Checked = false;
}
}
//aspx
function prioritySelection(sender) {
var e = document.getElementById(sender.id);
e = e.value;
if (e == 2 || e == 4 || e == 1 || e == 3) {
$('#<%=hdtest.ClientID%>').val(e);
$find("ContentPlaceHolder1_ContentPlaceHolder2_ModalPopupIncidentTypeChange").show();
}
}
I have two DataTables, DataTable1 sends some of its values to DataTable2. What I want to do is if DataTable1 values already exists in DataTable2, the values will not add to DataTable2.
I have here values from DataTable1
protected void ASPxGridView1_CustomButtonCallback(object sender, ASPxGridViewCustomButtonCallbackEventArgs e)
{
if (e.ButtonID != "ADD") return;
int id = e.VisibleIndex
int DeliveredQty = Convert.ToInt32(ASPxGridView1.GetRowValues(id, "Delivered Qty"));
int InventoryID = Convert.ToInt32(ASPxGridView1.GetRowValues(id, "InventoryID"));
Now I want to check the DataTable2 values if there's an existing InventoryID in the rows.
This is what I ended up with
int id = InventoryID;
DataTable dt = DataTable2;
DataRow[] dr = dt.Select(id.ToString());
if (dr == null)
{
"if it does not exist, values will be addded"
}
else
{
"prompt user that values exist"
}
What's the correct way to do this?
You can use Linq to check for a value in a DataTable column
bool valueExists = dt.AsEnumerable().Any(x => x.Field<string>("ColumnName") == "abcd");
How to count the no of records in Gridview which have some particular data in a column
name result
======== ======
krishna pass
sanjay pass
ajay fail
out put needed in grid view - above Gridview already present,according to that grid i have to make another grid to count results
result no
====== =====
pass 2
fail 1
in data row bound , i calculated
protected void GVKeywordReport_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
DataRow pr = ((DataRowView)e.Row.DataItem).Row;
int oldPos = Convert.ToInt32(pr["oldposition"]);
int newPos = Convert.ToInt32(pr["newposition"]);
GVKeywordReport.HeaderRow.Cells[3].Text = txtfrmdate.Text;
GVKeywordReport.HeaderRow.Cells[4].Text = txtEndDate.Text;
GVKeywordReport.HeaderRow.BackColor = ColorTranslator.FromHtml("#B3B300");
e.Row.Cells[0].BackColor = ColorTranslator.FromHtml("#B3B300");
e.Row.Cells[5].BackColor = ColorTranslator.FromHtml("#FFFFFF");
if (oldPos == newPos)
{
e.Row.BackColor = ColorTranslator.FromHtml("#FF950E");
e.Row.Cells[6].Text = "No Change";
nc= nc+1;
}
else if (oldPos > newPos)
{
e.Row.BackColor = ColorTranslator.FromHtml("#FFFFCC");
e.Row.Cells[6].Text = "Improved";
imprv= imprv+1;
}
else
{
e.Row.BackColor = ColorTranslator.FromHtml("#FF0000");
e.Row.Cells[6].Text = "Decreased";
decrs=decrs+1;
}
// e.Row.Cells[0].BackColor = ColorTranslator.FromHtml("#7DA647");
}
txt_TargetReached.Text = "0";
txtDecreased.Text =Convert.ToString(decrs);
On page index i am not able to hold the given value in the TextBox ,i have tried different logics but nothing is giving a correct result
here is Code
protected void gvViolationCodes_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
RememberOldValues();
//to rebind the data based on changed page index
violationCodePresenter.GetViolationCodesList(Convert.ToInt32(ddlStatus.SelectedValue), Convert.ToInt32(Session["LanguageID"]));
gvViolationCodes.PageIndex = e.NewPageIndex;
gvViolationCodes.DataBind();
RePopulateValues();
}
and the Method to store previous values is as follows
private void RememberOldValues()
{
DataTable dt = new DataTable();
dt.Columns.Add("row_index");
dt.Columns.Add("edited_value");
foreach (GridViewRow gvr in gvViolationCodes.Rows)
{
TextBox tb = (TextBox)gvr.FindControl("txtSeqNo");
HiddenField hf = (HiddenField)gvr.FindControl("HiddenField1");
if (tb.Text != hf.Value)
{
DataRow dr = dt.NewRow();
dr["row_index"] = gvr.RowIndex;
dr["edited_value"] = tb.Text;
dt.Rows.Add(dr);
}
}
if (dt.Rows.Count == 0 && Session["retain"] == null && Session["page-index"] == null)
{
Session["retain"] = null;
Session["page-index"] = null;
}
else if (dt.Rows.Count > 0 && Session["retain"] == null && Session["page-index"] == null)
{
Session["retain"] = dt;
Session["page_index"] = gvViolationCodes.PageIndex;
}
else if (Session["retain"] == null && Session["page-index"] == null)
{
Session["retain"] = dt;
Session["page_index"] = gvViolationCodes.PageIndex;
}
}
Use ViewState object to hold textbox values across page postback which is occurring because of paging in gridview.
I have 2 functions. In one function I have 2 viewstate values to get the direction
and sort order. Now I want to use this in another function.
I tried like this:
Session["a"] = Viewstate["a"];
Session["b"] = Viewstate["b"];
But it is returning NULL values:
private string SortDirection(string column)
{
string sortDirection = WebConstants.SortDirection.Ascending.ToString();
string sortExpression = ViewState["SortExpression"] as string;
if (sortExpression != null)
{
if (sortExpression == column)
{
string lastDirection = ViewState["SortDirection"] as string;
if ((lastDirection != null) && (lastDirection == WebConstants.SortDirection.Ascending.ToString()))
{
sortDirection = WebConstants.SortDirection.Descending.ToString();
}
}
}
ViewState["SortDirection"] = sortDirection;
ViewState["SortExpression"] = column;
return sortDirection;
}
What am I doing wrong?