顯示具有 Jquery 標籤的文章。 顯示所有文章
顯示具有 Jquery 標籤的文章。 顯示所有文章

2014年7月13日 星期日

[RESOLVED] How to bind DataList control within Web method in asp.net


Hi,


Can anyone help me in how to bind values to the datalist with in web method.


thanks



Hi,


That may not be possible. WebMethod or PageMethod are used to inform server or get data only


but not to create asp.net control or update it.


What u can do is, call WebMethod get DataSet and fill DataList at serverside itself.


http://www.aspdotnet-suresh.com/2011/05/aspnet-web-service-or-creating-and.html


or fill it by Ajax,


http://www.aspsnippets.com/Articles/Populate-ASPNet-DataList-by-binding-DataSet-Client-Side-using-jQuery-AJAX.aspx




Yes as raju has explained that web-methods are kind of Web-API calls and only service raw data not the server-side control binding etc. So, instead use jQuery based data control along with your web-methods.


Thanks 


[RESOLVED] How to bind DataList control within Web method in asp.net


Hi,


Can anyone help me in how to bind values to the datalist with in web method.


thanks



Hi,


That may not be possible. WebMethod or PageMethod are used to inform server or get data only


but not to create asp.net control or update it.


What u can do is, call WebMethod get DataSet and fill DataList at serverside itself.


http://www.aspdotnet-suresh.com/2011/05/aspnet-web-service-or-creating-and.html


or fill it by Ajax,


http://www.aspsnippets.com/Articles/Populate-ASPNet-DataList-by-binding-DataSet-Client-Side-using-jQuery-AJAX.aspx




Yes as raju has explained that web-methods are kind of Web-API calls and only service raw data not the server-side control binding etc. So, instead use jQuery based data control along with your web-methods.


Thanks 


[RESOLVED] HTML Editor Control


I'm am trying to replace an HTML Editor Control, similiar to what is seen on a blogging site. Where user has the option to  type, copy, cut, paste any text or image.  Most of the data will be coming from Microsoft Word 2010 documents or typed in manually.
I'm currently using the EO Editor Control and my users are finding issues in formatting the text. Sometimes when I save the data, the font type and size isnt being saved correctly. Also, noticed some issues with the bulleting.  Only other caveat is that I
have custom dropdownlists to enter client specific text into the form. This is a must. I must have user the ability to insert these custom text tags into their form.   Does anyone know of any good replacements or something I can extend to use to act similiar?
I've seen the AJAX one but not sure how extendable this is.



yes it is good to go with Ajax-HTML text editor, as it is open source you can extend or change it easily. or jQuery can be an other option.


have look at both


http://plugins.jquery.com/?s=text+editor


ajax


http://www.asp.net/ajaxLibrary/AjaxControlToolkitSampleSite/HTMLEditorExtender/HTMLEditorExtender.aspx


[RESOLVED] Enable field sorting when gridview datasource from code behind


Ok, I'm not sure how to get this to work. I have a gridview and I've enabled paging and sorting on my gridview. I set the two fields in question to be sortable headers. Here is what I have so far:


 


// Populate GridView using data table from code behind

private void GetData()
{
DataTable table = new DataTable();
// get the connection
string _cs = DBUtils.DBString;
using (SqlConnection conn = new SqlConnection(_cs))
{
// write the sql statement to execute
string sql = "SELECT [userid], [department] FROM [Employees] order by userid";
// instantiate the command object to fire
using (SqlCommand cmd = new SqlCommand(sql, conn))
{
// get the adapter object and attach the command object to it
using (SqlDataAdapter ad = new SqlDataAdapter(cmd))
{
// fire Fill method to fetch the data and fill into DataTable
ad.Fill(table);
}
}
}
GridView1.DataSource = table;
GridView1.DataBind();
}

// now for the code that is for sorting, I think this may be my problem.

protected void GridView1_Sorting(object sender, GridViewSortEventArgs e)
{
DataTable dataTable = GridView1.DataSource as DataTable;

if (dataTable != null)
{
DataView dataView = new DataView(dataTable);
dataView.Sort = e.SortExpression + " " + ConvertSortDirectionToSql(e.SortDirection);

GridView1.DataSource = dataView;
GridView1.DataBind();
}
}

// this code determines the selected sort order

private string ConvertSortDirectionToSql(SortDirection sortDirection)
{
string newSortDirection = String.Empty;

switch (sortDirection)
{
case SortDirection.Ascending:
newSortDirection = "ASC";
break;

case SortDirection.Descending:
newSortDirection = "DESC";
break;
}

return newSortDirection;
}



So, how do I get this sorting to work?



dataView. Sort = e. SortExpression + " " + ConvertSortDirectionToSql (e. SortDirection ); AFAIK, dv.sort= like : dataView. Sort = e. SortExpression + " Asc"

hi,


let the sorting work contains several steps:


1)set AllowSorting="True".


2)add SortExpression property in field.like:



3)define gridview sorting method.


Hope this helps



I'm using template fields not bound fields.



Ok, once I click the header, it sets the sort direction as ascending and retains that value no matter how many times I click on the header.



Hi,


You can use client side sorting mechanism. Refer the below urls which will use tablesorter & jquery for this because if we are doing it in server side we need to either fetch the data from db again or we need to keep it in session/other storage mechanism
for holding the data source of gridview won't be available on postback


http://dotnet-mcts.jecaestevez.com/2011/03/sort-aspnet-gridview-columns-using.html


http://www.iamraghuveer.com/2012/04/sorting-aspnet-gridview-control-using.html


Hope it helps




I finally figured this one out. Here's the link that helped me.


http://satindersinght.blogspot.com/2013/05/gridview-sorting-on-header-click-with.html


My relevant code sample:


 


protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
List list = new List();
if (ViewState["SelectedRecords"] != null)
{
list = (List)ViewState["SelectedRecords"];
}
foreach (GridViewRow row in GridView1.Rows)
{
String id = (String)GridView1.DataKeys[row.RowIndex].Value;
CheckBox checkBox = (CheckBox)row.FindControl("chkSelect");
if (checkBox.Checked)
{
if (!list.Contains(id))
{
list.Add(id);
}
}
if (!checkBox.Checked)
{
list.Remove(id);
}
}
ViewState["SelectedRecords"] = list;
GridView1.PageIndex = e.NewPageIndex;
GridView1.DataSource = Session["objects"];
GridView1.DataBind();
}

protected void GridView1_Sorting(object sender, GridViewSortEventArgs e)
{
GetData();
DataTable sourceTable = GridView1.DataSource as DataTable;
string sortingDirection = string.Empty;
if (direction == SortDirection.Ascending)
{
direction = SortDirection.Descending;
sortingDirection = "Desc";
}
else
{
direction = SortDirection.Ascending;
sortingDirection = "Asc";
}
DataView sortedView = new DataView(sourceTable);
sortedView.Sort = e.SortExpression + " " + sortingDirection;
Session["objects"] = sortedView;
DataView view = new DataView(sourceTable);
GridView1.DataSource = sortedView;
GridView1.DataBind();
}

public SortDirection direction
{
get
{
if (ViewState["directionState"] == null)
{
ViewState["directionState"] = SortDirection.Ascending;
}
return (SortDirection)ViewState["directionState"];
}
set
{ ViewState["directionState"] = value; }
}


[RESOLVED] HTML Editor Control


I'm am trying to replace an HTML Editor Control, similiar to what is seen on a blogging site. Where user has the option to  type, copy, cut, paste any text or image.  Most of the data will be coming from Microsoft Word 2010 documents or typed in manually.
I'm currently using the EO Editor Control and my users are finding issues in formatting the text. Sometimes when I save the data, the font type and size isnt being saved correctly. Also, noticed some issues with the bulleting.  Only other caveat is that I
have custom dropdownlists to enter client specific text into the form. This is a must. I must have user the ability to insert these custom text tags into their form.   Does anyone know of any good replacements or something I can extend to use to act similiar?
I've seen the AJAX one but not sure how extendable this is.



yes it is good to go with Ajax-HTML text editor, as it is open source you can extend or change it easily. or jQuery can be an other option.


have look at both


http://plugins.jquery.com/?s=text+editor


ajax


http://www.asp.net/ajaxLibrary/AjaxControlToolkitSampleSite/HTMLEditorExtender/HTMLEditorExtender.aspx


[RESOLVED] Enable field sorting when gridview datasource from code behind


Ok, I'm not sure how to get this to work. I have a gridview and I've enabled paging and sorting on my gridview. I set the two fields in question to be sortable headers. Here is what I have so far:


 


// Populate GridView using data table from code behind

private void GetData()
{
DataTable table = new DataTable();
// get the connection
string _cs = DBUtils.DBString;
using (SqlConnection conn = new SqlConnection(_cs))
{
// write the sql statement to execute
string sql = "SELECT [userid], [department] FROM [Employees] order by userid";
// instantiate the command object to fire
using (SqlCommand cmd = new SqlCommand(sql, conn))
{
// get the adapter object and attach the command object to it
using (SqlDataAdapter ad = new SqlDataAdapter(cmd))
{
// fire Fill method to fetch the data and fill into DataTable
ad.Fill(table);
}
}
}
GridView1.DataSource = table;
GridView1.DataBind();
}

// now for the code that is for sorting, I think this may be my problem.

protected void GridView1_Sorting(object sender, GridViewSortEventArgs e)
{
DataTable dataTable = GridView1.DataSource as DataTable;

if (dataTable != null)
{
DataView dataView = new DataView(dataTable);
dataView.Sort = e.SortExpression + " " + ConvertSortDirectionToSql(e.SortDirection);

GridView1.DataSource = dataView;
GridView1.DataBind();
}
}

// this code determines the selected sort order

private string ConvertSortDirectionToSql(SortDirection sortDirection)
{
string newSortDirection = String.Empty;

switch (sortDirection)
{
case SortDirection.Ascending:
newSortDirection = "ASC";
break;

case SortDirection.Descending:
newSortDirection = "DESC";
break;
}

return newSortDirection;
}



So, how do I get this sorting to work?



dataView. Sort = e. SortExpression + " " + ConvertSortDirectionToSql (e. SortDirection ); AFAIK, dv.sort= like : dataView. Sort = e. SortExpression + " Asc"

hi,


let the sorting work contains several steps:


1)set AllowSorting="True".


2)add SortExpression property in field.like:



3)define gridview sorting method.


Hope this helps



I'm using template fields not bound fields.



Ok, once I click the header, it sets the sort direction as ascending and retains that value no matter how many times I click on the header.



Hi,


You can use client side sorting mechanism. Refer the below urls which will use tablesorter & jquery for this because if we are doing it in server side we need to either fetch the data from db again or we need to keep it in session/other storage mechanism
for holding the data source of gridview won't be available on postback


http://dotnet-mcts.jecaestevez.com/2011/03/sort-aspnet-gridview-columns-using.html


http://www.iamraghuveer.com/2012/04/sorting-aspnet-gridview-control-using.html


Hope it helps




I finally figured this one out. Here's the link that helped me.


http://satindersinght.blogspot.com/2013/05/gridview-sorting-on-header-click-with.html


My relevant code sample:


 


protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
List list = new List();
if (ViewState["SelectedRecords"] != null)
{
list = (List)ViewState["SelectedRecords"];
}
foreach (GridViewRow row in GridView1.Rows)
{
String id = (String)GridView1.DataKeys[row.RowIndex].Value;
CheckBox checkBox = (CheckBox)row.FindControl("chkSelect");
if (checkBox.Checked)
{
if (!list.Contains(id))
{
list.Add(id);
}
}
if (!checkBox.Checked)
{
list.Remove(id);
}
}
ViewState["SelectedRecords"] = list;
GridView1.PageIndex = e.NewPageIndex;
GridView1.DataSource = Session["objects"];
GridView1.DataBind();
}

protected void GridView1_Sorting(object sender, GridViewSortEventArgs e)
{
GetData();
DataTable sourceTable = GridView1.DataSource as DataTable;
string sortingDirection = string.Empty;
if (direction == SortDirection.Ascending)
{
direction = SortDirection.Descending;
sortingDirection = "Desc";
}
else
{
direction = SortDirection.Ascending;
sortingDirection = "Asc";
}
DataView sortedView = new DataView(sourceTable);
sortedView.Sort = e.SortExpression + " " + sortingDirection;
Session["objects"] = sortedView;
DataView view = new DataView(sourceTable);
GridView1.DataSource = sortedView;
GridView1.DataBind();
}

public SortDirection direction
{
get
{
if (ViewState["directionState"] == null)
{
ViewState["directionState"] = SortDirection.Ascending;
}
return (SortDirection)ViewState["directionState"];
}
set
{ ViewState["directionState"] = value; }
}


[RESOLVED] HTML Editor Control


I'm am trying to replace an HTML Editor Control, similiar to what is seen on a blogging site. Where user has the option to  type, copy, cut, paste any text or image.  Most of the data will be coming from Microsoft Word 2010 documents or typed in manually.
I'm currently using the EO Editor Control and my users are finding issues in formatting the text. Sometimes when I save the data, the font type and size isnt being saved correctly. Also, noticed some issues with the bulleting.  Only other caveat is that I
have custom dropdownlists to enter client specific text into the form. This is a must. I must have user the ability to insert these custom text tags into their form.   Does anyone know of any good replacements or something I can extend to use to act similiar?
I've seen the AJAX one but not sure how extendable this is.



yes it is good to go with Ajax-HTML text editor, as it is open source you can extend or change it easily. or jQuery can be an other option.


have look at both


http://plugins.jquery.com/?s=text+editor


ajax


http://www.asp.net/ajaxLibrary/AjaxControlToolkitSampleSite/HTMLEditorExtender/HTMLEditorExtender.aspx


[RESOLVED] Enable field sorting when gridview datasource from code behind


Ok, I'm not sure how to get this to work. I have a gridview and I've enabled paging and sorting on my gridview. I set the two fields in question to be sortable headers. Here is what I have so far:


 


// Populate GridView using data table from code behind

private void GetData()
{
DataTable table = new DataTable();
// get the connection
string _cs = DBUtils.DBString;
using (SqlConnection conn = new SqlConnection(_cs))
{
// write the sql statement to execute
string sql = "SELECT [userid], [department] FROM [Employees] order by userid";
// instantiate the command object to fire
using (SqlCommand cmd = new SqlCommand(sql, conn))
{
// get the adapter object and attach the command object to it
using (SqlDataAdapter ad = new SqlDataAdapter(cmd))
{
// fire Fill method to fetch the data and fill into DataTable
ad.Fill(table);
}
}
}
GridView1.DataSource = table;
GridView1.DataBind();
}

// now for the code that is for sorting, I think this may be my problem.

protected void GridView1_Sorting(object sender, GridViewSortEventArgs e)
{
DataTable dataTable = GridView1.DataSource as DataTable;

if (dataTable != null)
{
DataView dataView = new DataView(dataTable);
dataView.Sort = e.SortExpression + " " + ConvertSortDirectionToSql(e.SortDirection);

GridView1.DataSource = dataView;
GridView1.DataBind();
}
}

// this code determines the selected sort order

private string ConvertSortDirectionToSql(SortDirection sortDirection)
{
string newSortDirection = String.Empty;

switch (sortDirection)
{
case SortDirection.Ascending:
newSortDirection = "ASC";
break;

case SortDirection.Descending:
newSortDirection = "DESC";
break;
}

return newSortDirection;
}



So, how do I get this sorting to work?



dataView. Sort = e. SortExpression + " " + ConvertSortDirectionToSql (e. SortDirection ); AFAIK, dv.sort= like : dataView. Sort = e. SortExpression + " Asc"

hi,


let the sorting work contains several steps:


1)set AllowSorting="True".


2)add SortExpression property in field.like:



3)define gridview sorting method.


Hope this helps



I'm using template fields not bound fields.



Ok, once I click the header, it sets the sort direction as ascending and retains that value no matter how many times I click on the header.



Hi,


You can use client side sorting mechanism. Refer the below urls which will use tablesorter & jquery for this because if we are doing it in server side we need to either fetch the data from db again or we need to keep it in session/other storage mechanism
for holding the data source of gridview won't be available on postback


http://dotnet-mcts.jecaestevez.com/2011/03/sort-aspnet-gridview-columns-using.html


http://www.iamraghuveer.com/2012/04/sorting-aspnet-gridview-control-using.html


Hope it helps




I finally figured this one out. Here's the link that helped me.


http://satindersinght.blogspot.com/2013/05/gridview-sorting-on-header-click-with.html


My relevant code sample:


 


protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
List list = new List();
if (ViewState["SelectedRecords"] != null)
{
list = (List)ViewState["SelectedRecords"];
}
foreach (GridViewRow row in GridView1.Rows)
{
String id = (String)GridView1.DataKeys[row.RowIndex].Value;
CheckBox checkBox = (CheckBox)row.FindControl("chkSelect");
if (checkBox.Checked)
{
if (!list.Contains(id))
{
list.Add(id);
}
}
if (!checkBox.Checked)
{
list.Remove(id);
}
}
ViewState["SelectedRecords"] = list;
GridView1.PageIndex = e.NewPageIndex;
GridView1.DataSource = Session["objects"];
GridView1.DataBind();
}

protected void GridView1_Sorting(object sender, GridViewSortEventArgs e)
{
GetData();
DataTable sourceTable = GridView1.DataSource as DataTable;
string sortingDirection = string.Empty;
if (direction == SortDirection.Ascending)
{
direction = SortDirection.Descending;
sortingDirection = "Desc";
}
else
{
direction = SortDirection.Ascending;
sortingDirection = "Asc";
}
DataView sortedView = new DataView(sourceTable);
sortedView.Sort = e.SortExpression + " " + sortingDirection;
Session["objects"] = sortedView;
DataView view = new DataView(sourceTable);
GridView1.DataSource = sortedView;
GridView1.DataBind();
}

public SortDirection direction
{
get
{
if (ViewState["directionState"] == null)
{
ViewState["directionState"] = SortDirection.Ascending;
}
return (SortDirection)ViewState["directionState"];
}
set
{ ViewState["directionState"] = value; }
}


[RESOLVED] HTML Editor Control


I'm am trying to replace an HTML Editor Control, similiar to what is seen on a blogging site. Where user has the option to  type, copy, cut, paste any text or image.  Most of the data will be coming from Microsoft Word 2010 documents or typed in manually.
I'm currently using the EO Editor Control and my users are finding issues in formatting the text. Sometimes when I save the data, the font type and size isnt being saved correctly. Also, noticed some issues with the bulleting.  Only other caveat is that I
have custom dropdownlists to enter client specific text into the form. This is a must. I must have user the ability to insert these custom text tags into their form.   Does anyone know of any good replacements or something I can extend to use to act similiar?
I've seen the AJAX one but not sure how extendable this is.



yes it is good to go with Ajax-HTML text editor, as it is open source you can extend or change it easily. or jQuery can be an other option.


have look at both


http://plugins.jquery.com/?s=text+editor


ajax


http://www.asp.net/ajaxLibrary/AjaxControlToolkitSampleSite/HTMLEditorExtender/HTMLEditorExtender.aspx


[RESOLVED] Enable field sorting when gridview datasource from code behind


Ok, I'm not sure how to get this to work. I have a gridview and I've enabled paging and sorting on my gridview. I set the two fields in question to be sortable headers. Here is what I have so far:


 


// Populate GridView using data table from code behind

private void GetData()
{
DataTable table = new DataTable();
// get the connection
string _cs = DBUtils.DBString;
using (SqlConnection conn = new SqlConnection(_cs))
{
// write the sql statement to execute
string sql = "SELECT [userid], [department] FROM [Employees] order by userid";
// instantiate the command object to fire
using (SqlCommand cmd = new SqlCommand(sql, conn))
{
// get the adapter object and attach the command object to it
using (SqlDataAdapter ad = new SqlDataAdapter(cmd))
{
// fire Fill method to fetch the data and fill into DataTable
ad.Fill(table);
}
}
}
GridView1.DataSource = table;
GridView1.DataBind();
}

// now for the code that is for sorting, I think this may be my problem.

protected void GridView1_Sorting(object sender, GridViewSortEventArgs e)
{
DataTable dataTable = GridView1.DataSource as DataTable;

if (dataTable != null)
{
DataView dataView = new DataView(dataTable);
dataView.Sort = e.SortExpression + " " + ConvertSortDirectionToSql(e.SortDirection);

GridView1.DataSource = dataView;
GridView1.DataBind();
}
}

// this code determines the selected sort order

private string ConvertSortDirectionToSql(SortDirection sortDirection)
{
string newSortDirection = String.Empty;

switch (sortDirection)
{
case SortDirection.Ascending:
newSortDirection = "ASC";
break;

case SortDirection.Descending:
newSortDirection = "DESC";
break;
}

return newSortDirection;
}



So, how do I get this sorting to work?



dataView. Sort = e. SortExpression + " " + ConvertSortDirectionToSql (e. SortDirection ); AFAIK, dv.sort= like : dataView. Sort = e. SortExpression + " Asc"

hi,


let the sorting work contains several steps:


1)set AllowSorting="True".


2)add SortExpression property in field.like:



3)define gridview sorting method.


Hope this helps



I'm using template fields not bound fields.



Ok, once I click the header, it sets the sort direction as ascending and retains that value no matter how many times I click on the header.



Hi,


You can use client side sorting mechanism. Refer the below urls which will use tablesorter & jquery for this because if we are doing it in server side we need to either fetch the data from db again or we need to keep it in session/other storage mechanism
for holding the data source of gridview won't be available on postback


http://dotnet-mcts.jecaestevez.com/2011/03/sort-aspnet-gridview-columns-using.html


http://www.iamraghuveer.com/2012/04/sorting-aspnet-gridview-control-using.html


Hope it helps




I finally figured this one out. Here's the link that helped me.


http://satindersinght.blogspot.com/2013/05/gridview-sorting-on-header-click-with.html


My relevant code sample:


 


protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
List list = new List();
if (ViewState["SelectedRecords"] != null)
{
list = (List)ViewState["SelectedRecords"];
}
foreach (GridViewRow row in GridView1.Rows)
{
String id = (String)GridView1.DataKeys[row.RowIndex].Value;
CheckBox checkBox = (CheckBox)row.FindControl("chkSelect");
if (checkBox.Checked)
{
if (!list.Contains(id))
{
list.Add(id);
}
}
if (!checkBox.Checked)
{
list.Remove(id);
}
}
ViewState["SelectedRecords"] = list;
GridView1.PageIndex = e.NewPageIndex;
GridView1.DataSource = Session["objects"];
GridView1.DataBind();
}

protected void GridView1_Sorting(object sender, GridViewSortEventArgs e)
{
GetData();
DataTable sourceTable = GridView1.DataSource as DataTable;
string sortingDirection = string.Empty;
if (direction == SortDirection.Ascending)
{
direction = SortDirection.Descending;
sortingDirection = "Desc";
}
else
{
direction = SortDirection.Ascending;
sortingDirection = "Asc";
}
DataView sortedView = new DataView(sourceTable);
sortedView.Sort = e.SortExpression + " " + sortingDirection;
Session["objects"] = sortedView;
DataView view = new DataView(sourceTable);
GridView1.DataSource = sortedView;
GridView1.DataBind();
}

public SortDirection direction
{
get
{
if (ViewState["directionState"] == null)
{
ViewState["directionState"] = SortDirection.Ascending;
}
return (SortDirection)ViewState["directionState"];
}
set
{ ViewState["directionState"] = value; }
}


[RESOLVED] HTML Editor Control


I'm am trying to replace an HTML Editor Control, similiar to what is seen on a blogging site. Where user has the option to  type, copy, cut, paste any text or image.  Most of the data will be coming from Microsoft Word 2010 documents or typed in manually.
I'm currently using the EO Editor Control and my users are finding issues in formatting the text. Sometimes when I save the data, the font type and size isnt being saved correctly. Also, noticed some issues with the bulleting.  Only other caveat is that I
have custom dropdownlists to enter client specific text into the form. This is a must. I must have user the ability to insert these custom text tags into their form.   Does anyone know of any good replacements or something I can extend to use to act similiar?
I've seen the AJAX one but not sure how extendable this is.



yes it is good to go with Ajax-HTML text editor, as it is open source you can extend or change it easily. or jQuery can be an other option.


have look at both


http://plugins.jquery.com/?s=text+editor


ajax


http://www.asp.net/ajaxLibrary/AjaxControlToolkitSampleSite/HTMLEditorExtender/HTMLEditorExtender.aspx


[RESOLVED] Enable field sorting when gridview datasource from code behind


Ok, I'm not sure how to get this to work. I have a gridview and I've enabled paging and sorting on my gridview. I set the two fields in question to be sortable headers. Here is what I have so far:


 


// Populate GridView using data table from code behind

private void GetData()
{
DataTable table = new DataTable();
// get the connection
string _cs = DBUtils.DBString;
using (SqlConnection conn = new SqlConnection(_cs))
{
// write the sql statement to execute
string sql = "SELECT [userid], [department] FROM [Employees] order by userid";
// instantiate the command object to fire
using (SqlCommand cmd = new SqlCommand(sql, conn))
{
// get the adapter object and attach the command object to it
using (SqlDataAdapter ad = new SqlDataAdapter(cmd))
{
// fire Fill method to fetch the data and fill into DataTable
ad.Fill(table);
}
}
}
GridView1.DataSource = table;
GridView1.DataBind();
}

// now for the code that is for sorting, I think this may be my problem.

protected void GridView1_Sorting(object sender, GridViewSortEventArgs e)
{
DataTable dataTable = GridView1.DataSource as DataTable;

if (dataTable != null)
{
DataView dataView = new DataView(dataTable);
dataView.Sort = e.SortExpression + " " + ConvertSortDirectionToSql(e.SortDirection);

GridView1.DataSource = dataView;
GridView1.DataBind();
}
}

// this code determines the selected sort order

private string ConvertSortDirectionToSql(SortDirection sortDirection)
{
string newSortDirection = String.Empty;

switch (sortDirection)
{
case SortDirection.Ascending:
newSortDirection = "ASC";
break;

case SortDirection.Descending:
newSortDirection = "DESC";
break;
}

return newSortDirection;
}



So, how do I get this sorting to work?



dataView. Sort = e. SortExpression + " " + ConvertSortDirectionToSql (e. SortDirection ); AFAIK, dv.sort= like : dataView. Sort = e. SortExpression + " Asc"

hi,


let the sorting work contains several steps:


1)set AllowSorting="True".


2)add SortExpression property in field.like:



3)define gridview sorting method.


Hope this helps



I'm using template fields not bound fields.



Ok, once I click the header, it sets the sort direction as ascending and retains that value no matter how many times I click on the header.



Hi,


You can use client side sorting mechanism. Refer the below urls which will use tablesorter & jquery for this because if we are doing it in server side we need to either fetch the data from db again or we need to keep it in session/other storage mechanism
for holding the data source of gridview won't be available on postback


http://dotnet-mcts.jecaestevez.com/2011/03/sort-aspnet-gridview-columns-using.html


http://www.iamraghuveer.com/2012/04/sorting-aspnet-gridview-control-using.html


Hope it helps




I finally figured this one out. Here's the link that helped me.


http://satindersinght.blogspot.com/2013/05/gridview-sorting-on-header-click-with.html


My relevant code sample:


 


protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
List list = new List();
if (ViewState["SelectedRecords"] != null)
{
list = (List)ViewState["SelectedRecords"];
}
foreach (GridViewRow row in GridView1.Rows)
{
String id = (String)GridView1.DataKeys[row.RowIndex].Value;
CheckBox checkBox = (CheckBox)row.FindControl("chkSelect");
if (checkBox.Checked)
{
if (!list.Contains(id))
{
list.Add(id);
}
}
if (!checkBox.Checked)
{
list.Remove(id);
}
}
ViewState["SelectedRecords"] = list;
GridView1.PageIndex = e.NewPageIndex;
GridView1.DataSource = Session["objects"];
GridView1.DataBind();
}

protected void GridView1_Sorting(object sender, GridViewSortEventArgs e)
{
GetData();
DataTable sourceTable = GridView1.DataSource as DataTable;
string sortingDirection = string.Empty;
if (direction == SortDirection.Ascending)
{
direction = SortDirection.Descending;
sortingDirection = "Desc";
}
else
{
direction = SortDirection.Ascending;
sortingDirection = "Asc";
}
DataView sortedView = new DataView(sourceTable);
sortedView.Sort = e.SortExpression + " " + sortingDirection;
Session["objects"] = sortedView;
DataView view = new DataView(sourceTable);
GridView1.DataSource = sortedView;
GridView1.DataBind();
}

public SortDirection direction
{
get
{
if (ViewState["directionState"] == null)
{
ViewState["directionState"] = SortDirection.Ascending;
}
return (SortDirection)ViewState["directionState"];
}
set
{ ViewState["directionState"] = value; }
}


[RESOLVED] HTML Editor Control


I'm am trying to replace an HTML Editor Control, similiar to what is seen on a blogging site. Where user has the option to  type, copy, cut, paste any text or image.  Most of the data will be coming from Microsoft Word 2010 documents or typed in manually.
I'm currently using the EO Editor Control and my users are finding issues in formatting the text. Sometimes when I save the data, the font type and size isnt being saved correctly. Also, noticed some issues with the bulleting.  Only other caveat is that I
have custom dropdownlists to enter client specific text into the form. This is a must. I must have user the ability to insert these custom text tags into their form.   Does anyone know of any good replacements or something I can extend to use to act similiar?
I've seen the AJAX one but not sure how extendable this is.



yes it is good to go with Ajax-HTML text editor, as it is open source you can extend or change it easily. or jQuery can be an other option.


have look at both


http://plugins.jquery.com/?s=text+editor


ajax


http://www.asp.net/ajaxLibrary/AjaxControlToolkitSampleSite/HTMLEditorExtender/HTMLEditorExtender.aspx


[RESOLVED] Enable field sorting when gridview datasource from code behind


Ok, I'm not sure how to get this to work. I have a gridview and I've enabled paging and sorting on my gridview. I set the two fields in question to be sortable headers. Here is what I have so far:


 


// Populate GridView using data table from code behind

private void GetData()
{
DataTable table = new DataTable();
// get the connection
string _cs = DBUtils.DBString;
using (SqlConnection conn = new SqlConnection(_cs))
{
// write the sql statement to execute
string sql = "SELECT [userid], [department] FROM [Employees] order by userid";
// instantiate the command object to fire
using (SqlCommand cmd = new SqlCommand(sql, conn))
{
// get the adapter object and attach the command object to it
using (SqlDataAdapter ad = new SqlDataAdapter(cmd))
{
// fire Fill method to fetch the data and fill into DataTable
ad.Fill(table);
}
}
}
GridView1.DataSource = table;
GridView1.DataBind();
}

// now for the code that is for sorting, I think this may be my problem.

protected void GridView1_Sorting(object sender, GridViewSortEventArgs e)
{
DataTable dataTable = GridView1.DataSource as DataTable;

if (dataTable != null)
{
DataView dataView = new DataView(dataTable);
dataView.Sort = e.SortExpression + " " + ConvertSortDirectionToSql(e.SortDirection);

GridView1.DataSource = dataView;
GridView1.DataBind();
}
}

// this code determines the selected sort order

private string ConvertSortDirectionToSql(SortDirection sortDirection)
{
string newSortDirection = String.Empty;

switch (sortDirection)
{
case SortDirection.Ascending:
newSortDirection = "ASC";
break;

case SortDirection.Descending:
newSortDirection = "DESC";
break;
}

return newSortDirection;
}



So, how do I get this sorting to work?



dataView. Sort = e. SortExpression + " " + ConvertSortDirectionToSql (e. SortDirection ); AFAIK, dv.sort= like : dataView. Sort = e. SortExpression + " Asc"

hi,


let the sorting work contains several steps:


1)set AllowSorting="True".


2)add SortExpression property in field.like:



3)define gridview sorting method.


Hope this helps



I'm using template fields not bound fields.



Ok, once I click the header, it sets the sort direction as ascending and retains that value no matter how many times I click on the header.



Hi,


You can use client side sorting mechanism. Refer the below urls which will use tablesorter & jquery for this because if we are doing it in server side we need to either fetch the data from db again or we need to keep it in session/other storage mechanism
for holding the data source of gridview won't be available on postback


http://dotnet-mcts.jecaestevez.com/2011/03/sort-aspnet-gridview-columns-using.html


http://www.iamraghuveer.com/2012/04/sorting-aspnet-gridview-control-using.html


Hope it helps




I finally figured this one out. Here's the link that helped me.


http://satindersinght.blogspot.com/2013/05/gridview-sorting-on-header-click-with.html


My relevant code sample:


 


protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
List list = new List();
if (ViewState["SelectedRecords"] != null)
{
list = (List)ViewState["SelectedRecords"];
}
foreach (GridViewRow row in GridView1.Rows)
{
String id = (String)GridView1.DataKeys[row.RowIndex].Value;
CheckBox checkBox = (CheckBox)row.FindControl("chkSelect");
if (checkBox.Checked)
{
if (!list.Contains(id))
{
list.Add(id);
}
}
if (!checkBox.Checked)
{
list.Remove(id);
}
}
ViewState["SelectedRecords"] = list;
GridView1.PageIndex = e.NewPageIndex;
GridView1.DataSource = Session["objects"];
GridView1.DataBind();
}

protected void GridView1_Sorting(object sender, GridViewSortEventArgs e)
{
GetData();
DataTable sourceTable = GridView1.DataSource as DataTable;
string sortingDirection = string.Empty;
if (direction == SortDirection.Ascending)
{
direction = SortDirection.Descending;
sortingDirection = "Desc";
}
else
{
direction = SortDirection.Ascending;
sortingDirection = "Asc";
}
DataView sortedView = new DataView(sourceTable);
sortedView.Sort = e.SortExpression + " " + sortingDirection;
Session["objects"] = sortedView;
DataView view = new DataView(sourceTable);
GridView1.DataSource = sortedView;
GridView1.DataBind();
}

public SortDirection direction
{
get
{
if (ViewState["directionState"] == null)
{
ViewState["directionState"] = SortDirection.Ascending;
}
return (SortDirection)ViewState["directionState"];
}
set
{ ViewState["directionState"] = value; }
}


[RESOLVED] Paging Issue in Gridview


Hi 


I am currently working on the showing all users in gridview. I have used jquery autocomplete on the textbox (outside gridvew in other panel) when user type any name then gridview is showing the correct issue but i am getting error on impelmenting the paging
on the gridview .


can somebody help me on this.



many thanks



this auto search is searching only on the first page not on every page in gridview.


[RESOLVED] Checkbox


i,ve a repeater


then datalist


and then checkbox,textbox and redaio button



                    runat="server">




<%#GetGroupName(Eval("MENU_MODIFIER_GROUP_NAME_TRANSLATION_ID").ToString().Trim())%>
[Free :
<%#GetFreeQuantity(Eval("MENU_MODIFIER_GROUP_ID").ToString().Trim())%>
]   [max:
<%#GetMaxQuantity(Eval("MENU_MODIFIER_GROUP_ID").ToString().Trim())%>
]





<%-- ID="chkItemOptionalModifiers" OnSelectedIndexChanged="chkItemOptionalModifiers_SelectedIndexChanged"
runat="server">
--%>














LH
Full
RH







how i can get the valuse of textbox,checkbox,hiddenfiels.... in jquery..





hi nafees,


as you have used css-classes for both check-box and text-box, so, you can use these with jQuery selectors, like this,


$(".chkList").each( function(){ //your code } );
$(".spinnnerOptional").each( function(){ //your code } );

thanks


[RESOLVED] How to use jquery efect on DataList control of asp.net


Hi,


I want to apply jquery effect on DataList view's Item template.For example, when i mouse hover on the template ,button and others effect will appear .




Try the code shown in the link below. But, you need to customize it to your needs. It would help you understand the technique you need to follow to accomplish the task you need to do


http://forums.asp.net/t/1654861.aspx/1



hi,


I made a test . you can try it .


















code behind:


 public partial class MyDataList : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
List list = new List(){
new Student{StudentID="1111"},new Student{StudentID="2222"},
new Student{StudentID="333"},new Student{StudentID="444"},
new Student{StudentID="555"},new Student{StudentID="666"}
};
DataList1.DataSource = list;

DataList1.DataBind();
}
}
}
public class Student
{
private string studentID;

public string StudentID
{
get { return studentID; }
set { studentID = value; }
}
private string studentName;

public string StudentName
{
get { return studentName; }
set { studentName = value; }
}
}




if I repeat the column 3, the button appears in every item of the row.


I want to show the Button on a individual item , when i repeat column...



please help me.


[RESOLVED] Paging Issue in Gridview


Hi 


I am currently working on the showing all users in gridview. I have used jquery autocomplete on the textbox (outside gridvew in other panel) when user type any name then gridview is showing the correct issue but i am getting error on impelmenting the paging
on the gridview .


can somebody help me on this.



many thanks



this auto search is searching only on the first page not on every page in gridview.


[RESOLVED] Checkbox


i,ve a repeater


then datalist


and then checkbox,textbox and redaio button



                    runat="server">




<%#GetGroupName(Eval("MENU_MODIFIER_GROUP_NAME_TRANSLATION_ID").ToString().Trim())%>
[Free :
<%#GetFreeQuantity(Eval("MENU_MODIFIER_GROUP_ID").ToString().Trim())%>
]   [max:
<%#GetMaxQuantity(Eval("MENU_MODIFIER_GROUP_ID").ToString().Trim())%>
]





<%-- ID="chkItemOptionalModifiers" OnSelectedIndexChanged="chkItemOptionalModifiers_SelectedIndexChanged"
runat="server">
--%>














LH
Full
RH







how i can get the valuse of textbox,checkbox,hiddenfiels.... in jquery..





hi nafees,


as you have used css-classes for both check-box and text-box, so, you can use these with jQuery selectors, like this,


$(".chkList").each( function(){ //your code } );
$(".spinnnerOptional").each( function(){ //your code } );

thanks


[RESOLVED] How to use jquery efect on DataList control of asp.net


Hi,


I want to apply jquery effect on DataList view's Item template.For example, when i mouse hover on the template ,button and others effect will appear .




Try the code shown in the link below. But, you need to customize it to your needs. It would help you understand the technique you need to follow to accomplish the task you need to do


http://forums.asp.net/t/1654861.aspx/1



hi,


I made a test . you can try it .


















code behind:


 public partial class MyDataList : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
List list = new List(){
new Student{StudentID="1111"},new Student{StudentID="2222"},
new Student{StudentID="333"},new Student{StudentID="444"},
new Student{StudentID="555"},new Student{StudentID="666"}
};
DataList1.DataSource = list;

DataList1.DataBind();
}
}
}
public class Student
{
private string studentID;

public string StudentID
{
get { return studentID; }
set { studentID = value; }
}
private string studentName;

public string StudentName
{
get { return studentName; }
set { studentName = value; }
}
}




if I repeat the column 3, the button appears in every item of the row.


I want to show the Button on a individual item , when i repeat column...



please help me.