C# - GridView Sort Expression Must Return Not Empty Data

Mar 1, 2010

My program running good. But i try to add up-down icon on my gridView header. but if i make it, My break point should drop below "if comparison" For example; field.SortExpression=Category but every time CustomersGridView.SortExpression is empty when gridview.SortExp is not empty.

foreach (DataControlField field in CustomersGridView.Columns)
{
if (field.SortExpression == CustomersGridView.SortExpression)
{
return CustomersGridView.Columns.IndexOf(field);
}
}
i need :
foreach (DataControlField field in CustomersGridView.Columns)
{
if (field.SortExpression == "Category")
{
return 2;
}
}
CustomersGridView.SortExpression must not be empty!!!!!
MY source:
<head runat="server">
<title></title>
<link type="text/css" href="StyleSheet.css" rel="stylesheet" />
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode="Conditional">
<ContentTemplate>
<asp:GridView
ID="gvCustomers" runat="server" CssClass="tablestyle"
AllowSorting="true"
OnRowDataBound="GvCustomers_RowDataBound" AutoGenerateColumns="false">
<AlternatingRowStyle CssClass="altrowstyle" />
<HeaderStyle CssClass="headerstyle" />
<RowStyle CssClass="rowstyle" />
<Columns>
<asp:BoundField HeaderText="Kategori" DataField="Category" SortExpression="Category" />
<asp:BoundField HeaderText="Tarih" DataField="Date" SortExpression="Date" />
</Columns>
</asp:GridView>
</ContentTemplate>
</asp:UpdatePanel>
protected void GvCustomers_RowDataBound(object sender, GridViewRowEventArgs e)
{
GridView gridView = (GridView)sender;
if (gridView.SortExpression.Length > 0)
{
int cellIndex = -1;
foreach (DataControlField field in gridView.Columns)
{
if (field.SortExpression == gvCustomers.SortExpression)
{
cellIndex = gridView.Columns.IndexOf(field);
break;
}
}
if (cellIndex > -1)
{
if (e.Row.RowType == DataControlRowType.Header)
{
// this is a header row,
// set the sort style
e.Row.Cells[cellIndex].CssClass +=
(gridView.SortDirection == SortDirection.Ascending
? " sortascheader" : " sortdescheader");
}
else if (e.Row.RowType == DataControlRowType.DataRow)
{
// this is an alternating row
e.Row.Cells[cellIndex].CssClass +=
(e.Row.RowIndex % 2 == 0
? " sortaltrow" : " sortrow");
}
}
}
}

View 1 Replies


Similar Messages:

Forms Data Controls :: Gridview Sort Expression - How To Reset A Gridview Or Prevent It From Doing A Sort

Sep 23, 2010

Just spent about 8 hours googling and looking through this forum for a solution on how to make sure that I can dynamically sort. Here is the situation.

I have 1 Gridview that displays 10 different scenarios based on what button is clicked.

I am also returning only top 10 records. I am doing all of the data binding pragmatically. So I have BoundFields, HyperLinkFields etc.

I also want to sort some records. When I change DataSource SQL statement the gridview somehow remembers what the last sort value was and it errors out saying that value "x" cannot be sorted because it does not exists.

I tried this:

Tried setting gridview1.sqldatasourceid = null; gridview1.allowsorting = false; gridview1.databind();

Here I get an error that says that the data source does not support sorting? Doesnt it say gridview1.allowsorting = false;

I also tried gridview1.sort("", SortDirection.Ascending); This does nothin... except query my database one more time because i have a onSorting event that looks like this:

[Code]....

Here is an example of just one of those SLQ statements inside GetSQLQuery:

[Code]....

View 1 Replies

Forms Data Controls :: Modifying A Gridview Sort Expression?

Jan 31, 2011

I have a gridview of the following form below

ID Expirydate
A 1/02/2011
B 2/02/2009
C 3/01/2009

and I would like to modify my sort expression so that when the expirydate header is clicked on, it will make all those id that has expired pop to the top . In this case, we will have the following as the results

ID Expirydate
B 2/02/2009
C 3/01/2009
A 1/02/2011

View 6 Replies

Retrieving Gridview's Sort Expression And Direction Via Javascript?

Aug 16, 2010

I was given help in a previous topic located here: Accessing Gridview In Another Form In this topic I had gridview rows that are selectable and a search window that returned search results. We found a way for me to select a row in the parent window of the search one. My issue now is that when the parent windows gridview is sorted, the function no longer selects the correct row. I was wondering if there was any way to access the gridviews sort expression and direction, or some other way I can do this so it accounts for sorting. Relavent code is as follow: This is in my parent window

<script type = "text/javascript">
function selectRow(index)
{
//Retrieve a reference to the table that represents the GridView
var gridView = document.getElementById('<%=gvSideList.ClientID%>');
if(gridView)
{
//If able to get a reference to the table representing the GridView...
var doPostbackArgument='Select$'+index;
__doPostBack('<%=gvSideList.ClientID%>',doPostbackArgument);
}
}

This is in the child window

<script type = "text/javascript" >
function selecttherow(index)
{
window.opener.selectRow(index);
}
</script>
protected void gvresults_SelectedIndexChanged(object sender, EventArgs e)
{
//declare variables
GridViewRow row;
int index;
int id;
//retrieve index, row, and id from gvresults
index = gvresults.SelectedIndex;
row = gvresults.Rows[index];
id = Convert.ToInt32(row.Cells[5].Text);
//fill a datatable from general with id's for selection
SqlCommand cmd = new SqlCommand("SELECT ID FROM General", csbg);
cmd.Parameters.AddWithValue("@id", id);
SqlDataAdapter da = new SqlDataAdapter(cmd);
DataTable dt = new DataTable();
da.Fill(dt);
//loop through the dt and find the index of the matching id from the search window
for (int i = 0; i < dt.Rows.Count; i++)
{
if (dt.Rows[i]["ID"].Equals(id))
{
//execute script to select the matching row in the dataentry page
string script = "";
script += "selecttherow(";
script += i;
script += ");";
ScriptManager.RegisterClientScriptBlock(this.Page, this.GetType(), "selecting", script, true);
break;
}
}
}

Let me know if you need me to further clarify anything.

View 7 Replies

Posted Data Always Return Empty From Server

Jan 25, 2011

i always got the empty string in form data posting. can you describe what the hell happened in my code? always got the empty string to insert to SQL server even it is drop down list selected value is empty. Is this the error in visual studio cause sometimes i can get the value and sometimes can't (inconsistent!!!)

Protected Function sqlparameter_insert_newscat() As SqlParameter()
Dim sqlparam(4) As SqlParameter
Dim ddlstatus As Boolean
If rbActive.Items(0).Selected = True Then
[code]...

View 2 Replies

Forms Data Controls :: Getting Text As Empty String When Gridview Cell Is Empty?

Feb 19, 2010

I have a gridview with two bound fields. On clicking a button i want to display the values in first row of gridview in two textboxes. But if gridview cell is empty i am getting the text in textbox to which the value of cell is given as -' 'i know my problem will be solved if i use the template fields instead. But i want a solution while maintaining the bound fields ,if any.

View 2 Replies

Web Forms :: Regular Expression For Empty Textbox?

Jun 16, 2010

I have a problem with regular expression because I want to validate a textbox and I want that mark the error text when the textbox be empty.

View 1 Replies

Web Forms :: Regular Expression For Empty TextBox

Nov 20, 2010

I am using regex for server side validations.

I am facing a problem with regex. I want to check for sepecial characters like ><*&()%$@!~+...

I need to filter these special charecters...but the problem is in my 10 textboxes there only 3 are required...

I can submit the form without entering anything...but my regex is not allowing me to submit the form without giving a space from keyboard...

I just want to check for special charecters and empty textbox without giving a spacebar...

I just check these sites(http://regexlib.com/ and http://www.regular-expressions.info/) and read some documentation on regex...its kind of confusing....

Here is my regex for Middlename: ^[a-zA-Z''-'s]|[ ]{1,40}$ its worked but its not correct....then I changed it to ^[a-zA-Z''-'sd*]{1,40}$ this also not taking emptytextbox without giving a space...

My Goal:

In most of the textboxes I need to allow only numbers and - # _ in some textboxes....

For Address: need to allow alphabets and numbers and #-_' "

City: numbers and alphabets no special chars...

Main problem is I can write regex for most of these stuff but need to all textboxes without entering anything (empty textboxes).My work got stoped due to this.

View 1 Replies

Web Forms :: Expression Validator For Empty String

Dec 19, 2010

Is there any way to use a validator that shows an error mesagge, if the user leaves a textbox blank (empty string)? Note: in this case I can use RequiredFieldValidator, because the control I want to check for empty string is on a modalpopup (which is not visible most of the time) and the RequiredFieldValidator then blocks the Buttons on the rest of the (visible) page.

View 1 Replies

Web Forms :: Regular Expression That Validates Empty Strings

Oct 16, 2010

I'm trying to write a regular expression that allows positive & negative floating point numbers, but doesn't allow empty strings and characters.I have managed to create this

[Code]....

but it allows empty strings and I can't figure out how to add [+-].

My program is a web app which asks the user to input a temperature.

View 2 Replies

Web Forms :: Validate Empty Textbox With Regular Expression

Jun 16, 2010

I want That validate the textbox so this no be empty I put that

"[ws]{1,50}"

But I want that the error mark when the textbox be empty.

View 4 Replies

Regular Expression Validator Does Not Validate Empty Textbox?

Jun 30, 2010

I would like to validate the textbox for specific text and it must not be blank. But the regular expression validator is not validating if the text box is BLANK. However, it validates if I type something in the text box.

How can I make regular expression to trigger even if the text box is empty?

Should I use Required Validator + Regex Validator at the same time?

<asp:TextBox ID="txtcard" runat="server" MaxLength="16"></asp:TextBox>
<asp:RegularExpressionValidator ID="RegularExpressionValidator2" runat="server"
ControlToValidate="txtcard" ErrorMessage="Please type credit card no"
ValidationExpression="^d{16}$"></asp:RegularExpressionValidator>

View 3 Replies

Forms Data Controls :: How To Sort Data In GirdView Via Sort Icons Clicks

Feb 28, 2010

i read Matt Berseth article also i downloaded this source. But i can not do sorting event. Everything is ok but sorting is not working.

[Code]....

View 3 Replies

ADO.NET :: Return Value When Empty Table?

Oct 19, 2010

I have the following code that i call from the page behind code.

when no records are in the table i get an error message

invalidcastexception

conversion from type DBNULL to type Decimal is not valid

I would prefare if the procedure did not throw this error message and returned a value to notify me that no records found when zero records returned

Public Shared Function invoicetotal(ByVal CustEmail As String) As Decimal
' Dim selectcommand As New SqlCommand
Dim CONNECTION As SqlConnection = MaintainDB.GetConnectionString
Dim sel As String _

[Code]....

View 2 Replies

Return An Empty Sqlconnection Value?

May 7, 2010

I have th following code:

[Code]....

I got any error from the code, saying 'not all code path return a value', i suspect it is the catch block doesnt return a value. If so, what value should i return?

View 4 Replies

Forms Data Controls :: How To Change Sort Column Header Text And Retain The Sort Link

Jun 3, 2010

I have a simple dynamic gridview with following code -

GV = new GridView();

View 3 Replies

Forms Data Controls :: Gridview Sort Manually With Button Outside Of Gridview?

Jan 18, 2011

I have a gridview with data. I want a button which is not part of the gridview. Then if I press a button the gridview is sorted by two colums. i.e column1 ascending column2 descending.

I am not looking to work with a Sqldatasource as I use a data access layer. So the sort would have to be from a datatable and databind or directly with the gridview.

View 3 Replies

C# - Linq Expression To Return A List Of Strings Based On Field Count?

Nov 11, 2010

Say I have a table Comments with these columns: Id, Comment, Category, CreatedDate, CommenterIdI want to get the top 5 categories from the Comments table (based on the count of each category in that table). How can I do this in linq, to return either List or IQueryable?

View 2 Replies

Return All Values From Table If Query String Is Empty

Jan 1, 2010

I have a page that lists products from a table based on the querystring. So if I say foo.aspx?fam=1 all the products from family 1 will be listed. How can I make my code list all the values if query string is empty? My SQL command would have to be different...can't really see how I can do this.

<asp:SqlDataSource ID="ds_produtos" runat="server"
ConnectionString="<%$ ConnectionStrings:LocalSqlServer2 %>"
SelectCommand="SELECT DISTINCT [IdProduct], [Name], [Description], [IdFamily], [Price], [Stock] FROM [Product] WHERE ([IdFamily] = @IdFamily )">
<SelectParameters>
<asp:QueryStringParameter Name="IdFamily" QueryStringField="fam" Type="Int32" />
</SelectParameters>
</asp:SqlDataSource>

View 2 Replies

MVC :: FileStreamResult Return Empty File When It Is Redirected From Another Method?

Mar 25, 2011

I'm using ASP.MVC 3 with SSRS 2008 R2. I have some reports which I want to render as PDF document. So I my controller, I've got this code

[Code]....

Problem is, that this code returns empty pdf. If I call PrintReport directly from view, then it works. But when I call ReportSwitcher, which calls PrintReport, then it returns empty file.

View 19 Replies

SQL Server :: Return Results Where Field Is Not Null And Not Empty?

Feb 27, 2011

i want my query to return results where the field address is not empty or null

however, the query i have is still returning results where address is empty i.e. ' ' .

View 2 Replies

Sql Server - Textbox Control Doesn't Return NULL When It Is Empty

Mar 16, 2010

In reference to this question that I just asked, [URL] it appears that for some reason, an empty text box's value is not being fed to SQL Server as NULL, as it ought to be.

View 6 Replies

Asp.net - HttpContext.Current.Request.Url.AbsolutePath Return An Empty String?

Oct 6, 2010

When user requests http://localhost/WebApp1/Default.aspx, txtApplicationPath.Text should be assigned "/WebApp1", while txtAbsolutePath.Text should be assigned "http://localhost/WebApp1/Default.aspx", but instead both textboxes display empty strings.

[code]...

View 1 Replies

C# - Hide Empty Columns In A Gridview Without Knowing Which Will Be Empty?

Mar 4, 2011

I am working with a gridview that pulls data from a SQL database based on selections in dropdown lists. The source table has six columns for attributes of the selection, but depending on what is chosen, there could be anywhere from one to six of those that are empty (all null values). When the column is empty, I would like to have it hidden so the page is less clunky and confusing.

I've searched around for an answer for the past couple days, but what I have found so far is either related to hiding columns that you know are empty which I will not know or removing them in the SQL code which I think doesn't work if the column is called for in the gridview code and doesn't exist in the query.

View 3 Replies

Forms Data Controls :: How To Sort TemplateField Value In GridView

Jun 20, 2010

I want to create simple rating page where player's place,name and rating is displayed. I've created database with ID,Name and Rating Columns, binded Gridview to this database and created TemplateField "Place". With following code I've created numbered list for Place:

protected void Page_Load(object sender, EventArgs e){
for (int i = 0; i < GridView1.Rows.Count; i++)

View 4 Replies







Copyrights 2005-15 www.BigResource.com, All rights reserved