I followed this tutorial to allow a user to select a folder from their machine:
http://www.codeproject.com/Articles/21895/Directory-Browsing-in-ASP-Net
The problem is that every time I click on a node, it calls postback, which refreshes the page. So how do I stop postback being called every time?
<asp:TreeView ID="TreeView1" runat="server" Height="326px" ImageSet="XPFileExplorer"
NodeIndent="15" Width="292px">
<ParentNodeStyle Font-Bold="False" />
<HoverNodeStyle Font-Underline="True" ForeColor="#6666AA" />
<SelectedNodeStyle BackColor="#B5B5B5" Font-Underline="False" HorizontalPadding="0px"
VerticalPadding="0px" />
<NodeStyle Font-Names="Tahoma" Font-Size="8pt" ForeColor="Black" HorizontalPadding="2px"
NodeSpacing="0px" VerticalPadding="2px" />
<LeafNodeStyle ImageUrl="../images/folder.gif" />
</asp:TreeView>
Code behind:
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
TreeNode onjParent = new TreeNode("C:\\", "C:\\");
onjParent.PopulateOnDemand = true;
TreeView1.Nodes.Add(onjParent);
TreeView1.CollapseAll();
}
error.Visible = false;
TreeView1.TreeNodeExpanded += new TreeNodeEventHandler(TreeView1_TreeNodeExpanded);
TreeView1.SelectedNodeChanged += new EventHandler(TreeView1_SelectedNodeChanged);
}
void TreeView1_SelectedNodeChanged(object sender, EventArgs e)
{
_browseTextBox.Text = TreeView1.SelectedValue;
}
void TreeView1_TreeNodeExpanded(object sender, TreeNodeEventArgs e)
{
if (e.Node.Value.EndsWith("\\"))
{
AddNodes(e.Node.Value, e.Node);
}
}
private TreeNode AddNodes(string path, TreeNode parentNode)
{
FileList objList = new FileList(path, "*.*");
TreeNode node = new TreeNode(path, path);
for (int index = 0; index < objList.Directories.Length; index++)
{
string directory = objList.Directories[index];
TreeNode objChildNode = new TreeNode(directory, path + "\\" + directory + "\\");
objChildNode.PopulateOnDemand = true;
objChildNode.Target = "_blank";
parentNode.ChildNodes.Add(objChildNode);
}
foreach (string file in objList.Files)
{
TreeNode objChildNode = new TreeNode(file, path + "\\" + file);
parentNode.ChildNodes.Add(objChildNode);
}
return node;
}
protected void _browseButton_Click(object sender, ImageClickEventArgs e)
{
TreeView1.Nodes.Clear();
if (UpdateBrowseTextBoxWithSlash())
{
TreeNode onjParent = new TreeNode(_browseTextBox.Text, _browseTextBox.Text);
onjParent.PopulateOnDemand = true;
TreeView1.Nodes.Add(onjParent);
TreeView1.CollapseAll();
}
else
{
error.Visible = true;
error.Text = "Please Enter valid path";
}
}
private bool UpdateBrowseTextBoxWithSlash()
{
if (_browseTextBox.Text.Length != 0)
{
if (
-1 == _browseTextBox.Text.LastIndexOf(".") &&
!_browseTextBox.Text.Substring(_browseTextBox.Text.Length - 1, 1).Equals("/") &&
!_browseTextBox.Text.Substring(_browseTextBox.Text.Length - 1, 1).Equals("\\")
)
{
if (_browseTextBox.Text.Substring(0, 1).Equals("\\") || -1 != _browseTextBox.Text.IndexOf(":\\"))
_browseTextBox.Text += "\\";
else
_browseTextBox.Text += "/";
return System.IO.Directory.Exists(_browseTextBox.Text);
}
else if (_browseTextBox.Text.LastIndexOf(".") > 0)
{
return System.IO.File.Exists(_browseTextBox.Text);
}
}
return true;
}
Have you looked at Imperfect Solution To TreeView? The author provides an interesting idea to omit postback when selecting a node by manually setting the NavigateUrl and SelectAction of each TreeNode. From first glance, it appears logical. The only thing missing is that it is not recursive so it can only handle one node level at a time.
Related
I have a form where there is a ListBox, a textbox and four buttons called Save, Edit, Delete and Clear. I'm retrieving data from database and populating the ListBox. When I select one of the items in the ListBox, it is populated into the textbox. Now when I delete that item, there is nothing wrong, it works fine. But when I try to update that item, i.e. change the text in the textbox and then click the Edit button, there is problem. In the textbox, I can see the text is being changed, no problem with that, but when I debugged, I found in the backend, the textbox is still containing the old text and not the modified one.
What am I doing wrong?
Here's my UI code:
<asp:Content ID="Content3" ContentPlaceHolderID="MainContent" runat="server">
<h1>Employee Category</h1>
<table>
<td>
<asp:ListBox ID="listEmployeeCategory" runat="server" Height="164px" Width="210px" AutoPostBack="true" />
</td>
<td>
<table>
<tr>
<td>
<asp:Label ID="lblMessage" runat="server" Text="" Visible="false" />
</td>
</tr>
<tr>
<td>
<asp:Label ID="lblEmpCategoryName" runat="server" Text="Name: " Font-Bold="true" />
</td>
<td>
<asp:TextBox ID="txtEmpCategoryName" runat="server" />
</td>
<td>
<asp:RequiredFieldValidator ID="rqdEmpCategoryName" ControlToValidate="txtEmpCategoryName" ErrorMessage="Employee Category Name can't be empty!" Style="color:Red" runat="server" />
</td>
</tr>
</table>
<asp:Button ID="btnSave" Text="Save" runat="server" OnClick="btnSave_Click" />
<asp:Button ID="btnEdit" Text="Edit" runat="server" OnClick="btnEdit_Click" />
<asp:Button ID="btnDelete" Text="Delete" runat="server" OnClick="btnDelete_Click" />
<asp:Button ID="btnCancel" Text="Cancel" runat="server" />
</td>
</table>
</asp:Content>
And here's my backend code, for the sake of everyone's understanding, I'm posting my entire backend code (except the BL, DAL and DAO codes):
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using Shelter.DAO.MasterEntry;
using Shelter.BLL.MasterEntry;
namespace Shelter.UI.MasterEntry
{
public partial class EmployeeCategoryUI : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
LoadDataIntoListBox();
}
else
{
if (listEmployeeCategory.SelectedIndex != -1)
{
LoadDataIntoTextBox(Convert.ToInt32(listEmployeeCategory.SelectedValue));
}
}
}
private void LoadDataIntoTextBox(int val)
{
EmployeeCategory objEmployeeCategory = new EmployeeCategory();
EmployeeCategoryBLL empCategoryBLL = new EmployeeCategoryBLL();
objEmployeeCategory.ID = Convert.ToInt32(val);
DataTable EmpCategoryDt = new DataTable();
EmpCategoryDt = empCategoryBLL.RetrieveById(objEmployeeCategory);
txtEmpCategoryName.Text = EmpCategoryDt.Rows[0]["EmpCategoryName"].ToString();
}
private void LoadDataIntoListBox()
{
EmployeeCategory objEmployeeCategory = new EmployeeCategory();
EmployeeCategoryBLL empCategoryBLL = new EmployeeCategoryBLL();
DataSet EmployeeCategoryDs = new DataSet();
EmployeeCategoryDs = empCategoryBLL.RetreiveFromTable();
DataTable EmployeeCategoryDt = EmployeeCategoryDs.Tables[0];
DataRow tempRow = null;
foreach (DataRow tempRow_Variable in EmployeeCategoryDt.Rows)
{
tempRow = tempRow_Variable;
string rowText = tempRow["EmpCategoryName"] + "(" + tempRow["ID"] + ")";
string rowValue = tempRow["ID"].ToString();
listEmployeeCategory.Items.Add(new ListItem(rowText, rowValue));
}
}
protected void btnSave_Click(object sender, EventArgs e)
{
EmployeeCategory objEmployeeCategory = new EmployeeCategory();
EmployeeCategoryBLL empCategoryBLL = new EmployeeCategoryBLL();
objEmployeeCategory.EmpCategoryName = txtEmpCategoryName.Text;
bool isSave = empCategoryBLL.SaveToTable(objEmployeeCategory);
if (isSave)
{
int id = empCategoryBLL.ReturnLastInsertedId();
lblMessage.Visible = true;
lblMessage.Style.Add("Color", "Green");
lblMessage.Text = "Data saved successfully!";
string rowText = txtEmpCategoryName.Text + "(" +id.ToString()+ ")" ;
string rowValue = id.ToString();
listEmployeeCategory.Items.Add(new ListItem(rowText, rowValue));
txtEmpCategoryName.Text = "";
}
else
{
lblMessage.Visible = true;
lblMessage.Style.Add("Color", "Red");
lblMessage.Text = "Data saving failed!";
}
}
protected void btnEdit_Click(object sender, EventArgs e)
{
if (IsPostBack)
{
EmployeeCategory objEmployeeCategory = new EmployeeCategory();
EmployeeCategoryBLL empCategoryBLL = new EmployeeCategoryBLL();
objEmployeeCategory.EmpCategoryName = txtEmpCategoryName.Text;
objEmployeeCategory.ID = Convert.ToInt32(listEmployeeCategory.SelectedValue);
bool isEdit = empCategoryBLL.EditInTable(objEmployeeCategory);
if (isEdit)
{
int id = objEmployeeCategory.ID;
lblMessage.Visible = true;
lblMessage.Style.Add("Color", "Green");
lblMessage.Text = "Data edited successfully!";
}
else
{
lblMessage.Visible = true;
lblMessage.Style.Add("Color", "Red");
lblMessage.Text = "Data editing failed!";
}
}
}
protected void btnDelete_Click(object sender, EventArgs e)
{
if (IsPostBack)
{
EmployeeCategory objEmployeeCategory = new EmployeeCategory();
EmployeeCategoryBLL empCategoryBLL = new EmployeeCategoryBLL();
objEmployeeCategory.ID = Convert.ToInt32(listEmployeeCategory.SelectedValue);
bool isDelete = empCategoryBLL.DeleteFromTable(objEmployeeCategory);
if (isDelete)
{
lblMessage.Visible = true;
lblMessage.Style.Add("Color", "Green");
lblMessage.Text = "Data deleted successfully!";
listEmployeeCategory.Items.Remove(new ListItem(listEmployeeCategory.SelectedItem.Text, listEmployeeCategory.SelectedValue));
txtEmpCategoryName.Text = "";
}
else
{
lblMessage.Visible = true;
lblMessage.Style.Add("Color", "Red");
lblMessage.Text = "Data deleting failed!";
}
}
}
}
}
The txtEmpCategoryName.Text is still containing the old value, so whenever I try to update, it only takes the old value and not the modified value in the textbox. It seems that the TextChanged event is not working. What is the fix to this problem?
You can use Entity frame in Visual studio;
right click on your solution - select new Add - then New Project - C# -Class Library give it a project name and Click Ok to add a new project to your existing project.
rename your class to a meaning name such as BusinessLogic and make it public.
right click on the newly added project and select add new item, on your popup windows select data on the right panel then select ADO.NET Entity Data Model rename your edmx to a meaningful name and click on add. default option and click on next, point to your SQL database by clicking on the new Connection.
select your store procedure for populating your listbox and updating the description and click on Finish.
CREATE PROCEDURE Proc_name AS BEGIN SET NOCOUNT ON;
SELECT ID,Description FROM Table_Name END
CREATE PROCEDURE [dbo].[UpdateEmpCategoryBLL]
#ID int, #Description varchar(50) AS BEGIN
SET NOCOUNT ON;
UPDATE Question1 SET Description = #Description WHERE ID = #ID
END
In your class Implement your methods for populating listbox and updating the description
public class Wrapper
{
public static List EmployeeCategory()
{
try
{
return new LOOKUPEntities().empCategoryBLL().ToList();
}
catch (Exception)
{
throw;
}
}
public static void UpdateEmpCategory(int id, string description)
{
try
{
using (LOOKUPEntities client = new LOOKUPEntities())
{
client.UpdateEmpCategoryBLL(id, description);
}
}
catch (Exception)
{
throw;
}
}
}
copy the connection string from you app.config to your web.config. Then add your class library to your references by right clicking on your references and select add reference, select solution and click on add. Add also System.Data,Entity and click ok.
now;
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
BindListBox();
}
}
protected void BindListBox()
{
try
{
ListItem lstBox;
listEmployeeCategory.Items.Clear();
var query = Wrapper.EmployeeCategory();
foreach (var items in query)
{
lstBox = new ListItem(items.Description, items.ID.ToString());
listEmployeeCategory.Items.Add(lstBox);
}
}
catch(Exception ex)
{
lblMessage.Visible = true;
lblMessage.Style.Add("Color", "Red");
lblMessage.Text = "Data loading failed "+ ex +" !";
}
}
protected void listEmployeeCategory_SelectedIndexChanged(object sender, EventArgs e)
{
lblMessage.Visible = false;
try
{
Session["ID"] = listEmployeeCategory.SelectedValue.ToString();
txtEmpCategoryName.Text = listEmployeeCategory.SelectedItem.ToString();
}
catch (Exception ex)
{
lblMessage.Visible = true;
lblMessage.Style.Add("Color", "Red");
lblMessage.Text = "Loading session data failed " + ex + " !";
}
}
protected void btnEdit_Click(object sender, EventArgs e)
{
try
{
int id = int.Parse(Session["ID"].ToString());
Wrapper.UpdateEmpCategory(id, txtEmpCategoryName.Text.Trim());
lblMessage.Visible = true;
lblMessage.Style.Add("Color", "Green");
lblMessage.Text = "Data edited successfully!";
BindListBox();
txtEmpCategoryName.Text = string.Empty;
}
catch
{
lblMessage.Visible = true;
lblMessage.Style.Add("Color", "Red");
lblMessage.Text = "Data editing failed!";
}
}
done!
have asp repeater used to insert data into database
<asp:Repeater ID="Repeater1" runat="server">
<HeaderTemplate>
<div class="form-group" >
<div class="col-sm-2 control-label">
English
</div>
<center> <div class="col-sm-2 control-label">
Other Language
</div>
</center>
</div>
</HeaderTemplate>
<ItemTemplate>
<div class="form-group" >
<div class="col-sm-2 control-label"> <%# Eval("EnglishTranslation")%><asp:Label ID="Label1" runat="server" Text=' <%# Eval("StaticTRanslationId")%>' Visible="false"></asp:Label> </div>
<div class="col-sm-10"> <input id="Text1" type="text" class="form-control" runat="server" /></div>
</div>
</ItemTemplate>
</asp:Repeater>
i am using paging and its work good but when go to next or previous page data cleared in input text
i am trying to keep data in view stat but i get error this is my c# code
Type 'HR.tblstaticTranslation' in Assembly 'HR, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null' is not marked as serializable.
List<tblstaticTranslation> list = new List<tblstaticTranslation>();
ReturnDbForTesEntities db = new ReturnDbForTesEntities();
protected void Page_Load(object sender, EventArgs e)
{
list = db.tblstaticTranslation.Where(p => p.LanguageId == 1).ToList();
if (!IsPostBack)
{
GetItems();
retrivedata();
}
}
public int CurrentPage
{
get
{
//get current page number
object obj = this.ViewState["_CurrentPage"];
if (obj == null)
{
return 0;
}
else
{
return (int)obj;
}
}
set
{
//set in viewstate the current page number
this.ViewState["_CurrentPage"] = value;
}
}
private int GetItems()
{
//create new instance of PagedDataSource
PagedDataSource objPds = new PagedDataSource();
//set number of pages will appear
Ods = list;
objPds.PageSize = 10;
objPds.DataSource = Ods.ToList(); ;
objPds.AllowPaging = true;
int count = objPds.PageCount;
objPds.CurrentPageIndex = CurrentPage;
if (objPds.Count > 0)
{
//dispaly controls if there are pages
btnPrevious.Visible = true;
btnNext.Visible = true;
btnLastRecord.Visible = true;
btnFirstRecord.Visible = true;
lblCurrentPage.Visible = true;
lblCurrentPage.Text = "Page " +
Convert.ToString(CurrentPage + 1) + " of " +
Convert.ToString(objPds.PageCount);
}
else
{
//disable controls if there are no pages
btnPrevious.Visible = false;
btnNext.Visible = false;
btnLastRecord.Visible = false;
btnFirstRecord.Visible = false;
lblCurrentPage.Visible = false;
}
btnPrevious.Enabled = !objPds.IsFirstPage;
btnNext.Enabled = !objPds.IsLastPage;
btnLastRecord.Enabled = !objPds.IsLastPage;
btnFirstRecord.Enabled = !objPds.IsFirstPage;
Repeater1.DataSource = objPds;
Repeater1.DataBind();
//}
return count;
}
public List<tblstaticTranslation> Ods { get; set; }
void getdata()
{
List<tblstaticTranslation> liststatic = new List<tblstaticTranslation>();
tblstaticTranslation tbstatic = new tblstaticTranslation();
foreach (RepeaterItem item in Repeater1.Items)
{
string x = ((Label)item.FindControl("Label1")).Text;
HtmlInputText y = ((HtmlInputText)item.FindControl("Text1"));
if (y.Value .Trim() != string.Empty)
{
tbstatic.StaticTRanslationId = Convert.ToInt32(x);
tbstatic.OtherLanguageTranslation = y.Value ;
if (liststatic.Where(p => p.StaticTRanslationId == tbstatic.StaticTRanslationId).FirstOrDefault() == null)
{
liststatic.Add(tbstatic);
}
else
{
liststatic.Remove(liststatic.Where(p => p.StaticTRanslationId == tbstatic.StaticTRanslationId).FirstOrDefault());
liststatic.Add(tbstatic);
}
tbstatic = new tblstaticTranslation();
}
}
var dt = ConvertToDatatable(liststatic);
ViewState.Add("data", dt);
}
void retrivedata()
{
// List<tblstaticTranslation> data = new List<tblstaticTranslation>();
tblstaticTranslation[] newArrayname = (tblstaticTranslation[])ViewState["data"];
List<tblstaticTranslation> data = new List<tblstaticTranslation>();
if (newArrayname != null)
{
data = new List<tblstaticTranslation>(newArrayname);
}
DataTable dt = (DataTable)ViewState["data"];
DataView dataView = new DataView(dt.Select);
foreach (RepeaterItem items in Repeater1.Items)
{
string x = ((Label)items.FindControl("Label1")).Text;
HtmlInputText y = ((HtmlInputText)items.FindControl("Text1"));
int id = Convert.ToInt32(x);
if (dt.Select("StaticTRanslationId=" + id) != null)
{
y.Value = data.Where(p => p.StaticTRanslationId == id).FirstOrDefault().OtherLanguageTranslation;
}
}
}
public object ObjectControl { get; set; }
protected void btnFirstRecord_Click(object sender, EventArgs e)
{
CurrentPage = 0;
if (ViewState["data"] != null)
{
getdata();
// retrivedata();
}
else
{
// retrivedata();
getdata();
}
GetItems();
}
protected void btnLastRecord_Click(object sender, EventArgs e)
{
CurrentPage = GetItems() - 1;
if (ViewState["data"] != null)
{
getdata();
// retrivedata();
}
else
{
// retrivedata();
getdata();
}
GetItems();
}
protected void btnPrevious_Click1(object sender, EventArgs e)
{
CurrentPage -= 1;
if (ViewState["data"] != null)
{
getdata();
// retrivedata();
}
else
{
// retrivedata();
getdata();
}
GetItems();
}
protected void btnNext_Click(object sender, EventArgs e)
{
CurrentPage += 1;
if (ViewState["data"] != null)
{
getdata();
// retrivedata();
}
else
{
getdata();
// retrivedata();
}
GetItems();
}
When you want to keep some data in ViewState it's must be marked as serializable
If you have declare HR.tblstaticTranslation some where then use the serializable attribute as below
[Serializable()]
class tblstaticTranslation
{
...
}
I'm new to C# asp.net and I'm having trouble getting the selected item. Here is the code behind:
List<string> figuritasSelecionadas = new List<string>();
this.lblMensaje.Visible = false;
decimal total = 0;
foreach (ListItem lf in this.ListaFiguritas.Items)
{
if (lf.Selected)
{
figuritasSelecionadas.Add(lf.Text);
total += Decimal.Parse(lf.Value);
}
}
The problem here is that it doesn't matter which item is selected, because when it reaches the if the first item is marked as true. And I have no idea why it's doing this.
Here is how I load the ListBox:
private void cargarFiguritas()
{
List<Figurita> figuritas = Sistema.Instancia.figuritasQueFaltan(usuarioActivo);
this.ListaFiguritas.DataSource = figuritas;
this.ListaFiguritas.DataValueField = "Precio";
this.ListaFiguritas.DataTextField = "NumeroFigurita";
this.ListaFiguritas.DataBind();
Session["ListaFiguritas"] = figuritas;
}
protected void Page_Load(object sender, EventArgs e)
{
usuarioActivo = (string)Session["nombreUsuario"];
this.lblUsuario.Text = (string)Session["nombreUsuario"] + " tiene un total de: " + Session["Monedas"].ToString() + " monedas";
if (!IsPostBack)
{
cargarFiguritas();
}
}
Here is the aspx code:
<asp:ListBox ID="ListaFiguritas" runat="server" Height="180px" Width="110px" SelectionMode="Single">
</asp:ListBox>
I created a gridview using Telerik asp.net/ajax controls and when I run the app locally the grid works fine but when pushed to my server I get the same error for all of my methods:
ASP.default_aspx' does not contain a definition for 'IssuesGrid_OnItemUpdated' and no extension method 'IssuesGrid_OnItemUpdated' accepting a first argument of type 'ASP.default_aspx' could be found (are you missing a using directive or an assembly reference?)
I have tried deleting the reference in the grid and creating it again and letting VS create the method and then it'll work until I do that for all of the methods throwing the error and then it starts all over again.
Here is the aspx page:
<telerik:RadGrid ID="Issues" runat="server" CellSpacing="0" DataSourceID="GridSource" GridLines="None" Skin="Metro"
AllowPaging="True" AllowSorting="True" AllowFilteringByColumn="True" OnItemDataBound="Issues_OnItemDataBound"
PageSize="30" EnableLinqExpressions="false" EnableHeaderContextMenu="true" EnableHeaderContextFilterMenu="true"
AllowAutomaticDeletes="True" AllowAutomaticInserts="True" AllowAutomaticUpdates="True"
OnItemUpdated="Issues_OnItemUpdated" OnItemInserted="Issues_OnItemInserted" OnItemDeleted="Issues_OnItemDeleted"
OnItemCommand="Issues_OnItemCommand"
AutoGenerateColumns="False" ShowStatusBar="True" HorizontalAlign="Center" Height="900px">
And here are my methods in my cs file:
protected void Issues_OnItemUpdated(object sender, GridUpdatedEventArgs e)
{
if (e.Exception != null)
{
e.KeepInEditMode = true;
e.ExceptionHandled = true;
DisplayMessage(true, "Defect " + e.Item.OwnerTableView.DataKeyValues[e.Item.ItemIndex]["ID"] + " cannot be updated. Reason: " + e.Exception.Message);
}
else
{
DisplayMessage(false, "Defect " + e.Item.OwnerTableView.DataKeyValues[e.Item.ItemIndex]["ID"] + " updated");
}
}
protected void Issues_OnItemInserted(object source, GridInsertedEventArgs e)
{
if (e.Exception != null)
{
e.ExceptionHandled = true;
e.KeepInInsertMode = true;
DisplayMessage(true, "Defect cannot be inserted. Reason: " + e.Exception.Message);
}
else
{
DisplayMessage(false, "Defect inserted!");
}
}
protected void Issues_OnItemDeleted(object source, GridDeletedEventArgs e)
{
if (e.Exception != null)
{
e.ExceptionHandled = true;
DisplayMessage(true, "Defect " + e.Item.OwnerTableView.DataKeyValues[e.Item.ItemIndex]["ID"] + " cannot be deleted. Reason: " + e.Exception.Message);
}
else
{
DisplayMessage(false, "Defect " + e.Item.OwnerTableView.DataKeyValues[e.Item.ItemIndex]["ID"] + " deleted");
}
}
protected void Issues_OnItemCommand(object source, GridCommandEventArgs e)
{
if (e.CommandName == RadGrid.InitInsertCommandName) //"Add new" button clicked
{
var editColumn = (GridEditCommandColumn)Issues.MasterTableView.GetColumn("EditCommandColumn");
editColumn.Visible = false;
}
else if (e.CommandName == RadGrid.RebindGridCommandName && e.Item.OwnerTableView.IsItemInserted)
{
e.Canceled = true;
}
else
{
var editColumn = (GridEditCommandColumn)Issues.MasterTableView.GetColumn("EditCommandColumn");
if (!editColumn.Visible)
editColumn.Visible = true;
}
}
What's weird is I have an ondatabound method that is just fine and worked before any of these problems started and continues to work. I tried changing the 'object sender' to 'object source' but still a no go.
Here is the OnDataBound event:
protected void Issues_OnItemDataBound(object source, GridItemEventArgs e)
{
var gridDataItem = e.Item as GridDataItem;
if (gridDataItem != null)
{
var item = gridDataItem;
//Tooltips
if (!item.IsInEditMode)
{
var cell = item["Description"];
if (cell.Text.Length > 40)
{
var originaltext = cell.Text;
cell.Text = cell.Text.Remove(40) + "...";
cell.ToolTip = originaltext;
}
}
}
}
Any help on what I am doing wrong would be great!
Your code-behind (the .cs file) gets compiled into a dll when you deploy. Ensure that when you publish, these dll files are being copied over as well. This also means your published project should not have any .cs or .designer.cs files.
I have populated my checkboxlist on the fly via callback like this:
<dx:ASPxComboBox ID="ASPxComboBox_Prot" runat="server" DataSourceID="SqlDataSource_Prot"
TextField="LIBELLE" ValueField="NO_PROT" ValueType="System.Int32">
<ClientSideEvents SelectedIndexChanged="function(s, e) { cbp_ProtOrdos.PerformCallback(s.GetValue());}" />
</dx:ASPxComboBox>
</td>
</tr>
</table>
<dx:ASPxCallbackPanel ID="ASPxCallbackPanel_ProtOrdo" runat="server"
ClientInstanceName="cbp_ProtOrdos" OnCallback="cbp_ProtOrdo_Callback">
<PanelCollection>
<dx:PanelContent>
<dx:ASPxCheckBoxList ID="CheckBoxList_Ordo" runat="server" ClientInstanceName="CheckBoxList_Ordo" ValueType="System.Int32" TextField="LIBELLE" ValueField="NO_ORDO">
</dx:ASPxCheckBoxList>
<dx:ASPxButton ID="ASPxButton_ProtOrdoGen" runat="server"
Text="Générer ordonnance & Planifier pour infirmier"
OnClick="ASPxButton_ProtOrdoGen_Click"
EnableDefaultAppearance="false" BackColor="Yellow" CssClass="bt" Theme="BlackGlass" ForeColor="Black">
</dx:ASPxButton>
</dx:PanelContent>
</PanelCollection>
</dx:ASPxCallbackPanel>
And on server side code:
protected void cbp_ProtOrdo_Callback(object sender, DevExpress.Web.ASPxClasses.CallbackEventArgsBase e)
{
var panel = sender as ASPxCallbackPanel;
var cblist = panel.FindControl("CheckBoxList_Ordo") as ASPxCheckBoxList;
cblist.DataSource = Outils.Get_ProtOrdo(ASPxComboBox_Prot.Value.ToString());
cblist.DataBind();
}
It works fine, but now I want to get the value that had been checked by the user. So I add the button to do that.
protected void ASPxButton_ProtOrdoGen_Click(object sender, EventArgs e)
{
//TabPage oPage = ASPxPageControl_DosSoin.TabPages.FindByName("Surveillance");
//ASPxPanel oPanel = (ASPxPanel)oPage.FindControl("ASPxPanel_ListSurveil");
//ASPxRoundPanel oRoundPnl = (ASPxRoundPanel)oPanel.FindControl("ASPxRoundPanel_ProtOrdo");
//ASPxCallbackPanel ocbpPanel = (ASPxCallbackPanel)oRoundPnl.FindControl("ASPxCallbackPanel_ProtOrdo");
//ASPxCheckBoxList cblist = (ASPxCheckBoxList)ocbpPanel.FindControl("CheckBoxList_Ordo") as ASPxCheckBoxList;
List<string> selectItems_Ordo = new List<string>();
foreach (var oItem in CheckBoxList_Ordo.Items)
{
ListEditItem oNewChk = (ListEditItem)oItem;
if (oNewChk.Selected)
{
selectItems_Ordo.Add( oNewChk.Value.ToString());
}
}
foreach (var oItem in selectItems_Ordo)
{
if (DossierDuSoins.check_doublon_ordo(oItem.ToString(), Soin_Id) == 0)
DossierDuSoins.RamenerVal(DossierDuSoins.GetLibOrdo(oItem.ToString()), Soin_Id, oItem.ToString());
}
string TempId = "";
if (selectItems_Ordo.Count == 0)
{
lbl_err.Text = "Pas de médicament de sélectionné";
}
else
{
foreach (string selectItemId in selectItems_Ordo)
{
if (TempId != "")
TempId += ",";
TempId += selectItemId.ToString();
}
string AdrUrl = "Print_Ordo.aspx?SoinId=" + Soin_Id + "&SelId=" + TempId;
ClientScript.RegisterStartupScript(this.GetType(), "newWindow", String.Format("<script>window.open('{0}');</script>", AdrUrl));
}
}
The problem is that I can not get my checked value. Is that because the postback destroys all checkboxlists that I had constructed on the fly ?
Try this instead of using vars for selecting your checkbox list
foreach (ListItem yourItem in YourCheckBoxList.Items)
{
if (item.Selected)
{
// If the item is selected, Add to your list/ save to DB
}
else
{
// If item is not selected, do something else.
}
}