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();
}
}
Related
i have gridview with many col some of col will sum and display in total col using rowdatabound and it works only in view, but the problem when i try to edit using edit statement that gridview have this error appear (Troubleshooting exceptions: system.nullreferenceexception)
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
string val1 = e.Row.Cells[13].Text; //Gets the value in Column 1
string val2 = e.Row.Cells[14].Text; //Gets the value in Column 2
string val3 = e.Row.Cells[15].Text; //Gets the value in Column 3
string val4 = e.Row.Cells[16].Text; //Gets the value in Column 4
Label lblTotal = (Label)e.Row.Cells[12].FindControl("Label1"); //
float _val1, _val2, _val3, _val4;
float.TryParse(val1, out _val1);
float.TryParse(val2, out _val2);
float.TryParse(val3, out _val3);
float.TryParse(val4, out _val4);
float sum = _val1 + _val2 + _val3 + _val4;
lblTotal.Text += sum.ToString();
}
}
You need to check if the DataRow is in edit mode.
if (e.Row.RowType == DataControlRowType.DataRow)
{
if ((e.Row.RowState & DataControlRowState.Edit) > 0)
{
//row is in edit mode
}
else
{
//a normal row
}
}
In Telerik Load on demand RadOrgChart, I'm Loading data through server.
It will take up to 2 levels of data on every time click of each node. but data is coming properly from server,but problem is nodes not generated for those data. what should I do to get it properly?
private void CreateTeams() {
teams = new DataTable();
teams.Columns.Add("UniqueID");
teams.Columns.Add("ReportsTo");
teams.Columns.Add("Collapsed");
var myList = (List < NodeViewModel > ) Session["items"];
foreach(var nodeitem in myList) {
if (nodeitem.IsManager == true && nodeitem.level == 0) {
teams.Rows.Add(new string[] {
nodeitem.EmployeeBadge, null, "0"
});
} else {
teams.Rows.Add(new string[] {
nodeitem.EmployeeBadge, nodeitem.ManagerBadge, "1"
});
}
}
}
protected void Page_Load(object sender, EventArgs e) {
if (Request.Cookies["badgeName"] != null) {
var value = Request.Cookies["badgeName"].Value;
EmployeeRepository obj = new EmployeeRepository();
var myList = (List < NodeViewModel > ) Session["items"];
try {
obj.CreateLevel(new NodeViewModel() {
EmployeeBadge = value
}, myList);
logger.Info("OrgChart:Page_Load()::success");
} catch (Exception ex) {
logger.Error(string.Concat("OrgChart:Page_Load()::", ex.Message));
logger.Error(string.Concat("OrgChart:Page_Load()::", ex.StackTrace));
}
Response.Cookies["badgeName"].Expires = DateTime.Now.AddDays(-1);
}
CreateTeams();
CreateEmployees();
RadOrgChart1.GroupEnabledBinding.NodeBindingSettings.DataFieldID = "UniqueID";
RadOrgChart1.GroupEnabledBinding.NodeBindingSettings.DataFieldParentID = "ReportsTo";
RadOrgChart1.GroupEnabledBinding.NodeBindingSettings.DataCollapsedField = "Collapsed";
RadOrgChart1.GroupEnabledBinding.NodeBindingSettings.DataGroupCollapsedField = "Collapsed";
//RadOrgChart1.RenderedFields.NodeFields.Add(new Telerik.Web.UI.OrgChartRenderedField() { DataField = "Team" });
RadOrgChart1.GroupEnabledBinding.NodeBindingSettings.DataSource = teams;
RadOrgChart1.GroupEnabledBinding.GroupItemBindingSettings.DataFieldID = "EmployeeID";
RadOrgChart1.GroupEnabledBinding.GroupItemBindingSettings.DataFieldNodeID = "UniqueID";
RadOrgChart1.GroupEnabledBinding.GroupItemBindingSettings.DataTextField = "Name";
RadOrgChart1.GroupEnabledBinding.GroupItemBindingSettings.DataImageUrlField = "ImageUrl";
RadOrgChart1.GroupEnabledBinding.GroupItemBindingSettings.DataSource = employees;
RadOrgChart1.DataBind();
}
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);
protected void btnSave_Click(object sender, EventArgs e)
{
double a, b, c, d;
a = Convert.ToDouble(lblpurchasequantity.Text.ToString());
b = Convert.ToDouble(lblreceivedqty.Text.ToString());
c = Convert.ToDouble(txtreceivedquantity.Text.ToString());
d = b + c;
if (a >= d)
{
int? insertgrnorecords;
IFormatProvider provider = new System.Globalization.CultureInfo("en-CA", true);
String datetime = txtgoodsreceiveddate.Text.ToString();
DateTime dt = DateTime.Parse(datetime, provider, System.Globalization.DateTimeStyles.NoCurrentDateDefault);
objsupplyPL.goodsreceiveddate = dt;
objsupplyPL.productid1 = Hidden1.Value.ToString();
objsupplyPL.purchaseid = Hid_Sno1.Value.ToString();
objsupplyPL.vehicleno = (txtvehicleno.Text.Trim().ToString() == "" ? null : txtvehicleno.Text.Trim());
objsupplyPL.grno = txtgrno.Text.Trim().ToString();
objsupplyPL.dcno = txtdcno.Text.Trim().ToString();
objsupplyPL.username = Session["username"].ToString();
objsupplyPL.quantity = Convert.ToDouble(lblpurchasequantity.Text.ToString());
objsupplyPL.receivedquantity = Convert.ToDouble(txtreceivedquantity.Text.ToString());
objsupplyPL.totalreceived = Convert.ToDouble(lblreceivedqty.Text.ToString());
objsupplyPL.branch = Hid_Sno.Value;
insertgrnorecords = objsupplyBAL.insertgrnotorecords(objsupplyPL);
buildBranches();
clear();
ScriptManager.RegisterClientScriptBlock(this.Page, this.GetType(), "UpdateDetails", "alert('Save Successful');", true);
}
}
actuvally,this code for pop up window fields insertion,if i click save button,then it shows save succefully message..then it goes to general aspx page..In that GRNO button is having..then i click on GRNO two times,first time GRNO button is not fired,second time it will be fired
How to validate the column with same value, i try with this code :
protected void ASPxGridView1_RowValidating(object sender, DevExpress.Web.Data.ASPxDataValidationEventArgs e)
{
XPQuery<Inventory_Library.Inventory.t_barang_master> q = new XPQuery<Inventory_Library.Inventory.t_barang_master>(ses);
List<Inventory_Library.Inventory.t_barang_master> lst = (from o in q
where (o.nama_barang == e.OldValues["nama_barang"] && o.kode_barang == e.OldValues["kode_barang"])
select o).ToList<Inventory_Library.Inventory.t_barang_master>();
if (lst.Contains(e.OldValues["nama_barang"]))
{
e.RowError = "Nama barang yang anda masukkan telah terdaftar dalam sistem";
}
else if (lst.Contains(e.OldValues["kode_barang"]))
{
e.RowError = "Kode barang yang anda masukkan telah terdaftar dalam sistem";
}
}
but that's not work, how to solve this problem, thanks for the answer
problem solve, if you find the same problem with me, you can use this code:
protected void ASPxGridView1_RowValidating(object sender, DevExpress.Web.Data.ASPxDataValidationEventArgs e)
{
XPQuery<Inventory_Library.Inventory.t_kategori> q = new XPQuery<Inventory_Library.Inventory.t_kategori>(ses);
List<Inventory_Library.Inventory.t_kategori> lst = (from o in q
where (o.kategori == e.NewValues["kategori"])
select o).ToList<Inventory_Library.Inventory.t_kategori>();
if (lst.Count > 0)
{
e.RowError = "Kategori yang anda masukkan telah terdaftar dalam sistem";
}
}