RadComboBox of telerik lost SelectedValue - c#

I have a RadComboBox of Telerik that lost the selectedValue, when I try to insert in DB. It has the value at all time during the execution, but when I click the save button I see that the RadComboBox lost the SelectedValue only, it doesn't lose the text only the int value. I use asp.net and c#.
Please help me with your comments and recommendation. Thanks.
<!-- Definition of cbProg in page aspx-->
<tr style="display: table-row;">
<td style="display: table-cell; vertical-align: inherit">
<div style="left: 210px; position: absolute; top: 140px;">
<label for="cbProg">Programa:</label>
<div style="left: 65px; position: absolute; top: -10px;">
<telerik:RadTextBox ID="txtProg" runat="server" Width="40px" Height="25px" Enabled="true" MaxLength="2"
BorderColor="#C9D9F8" BorderStyle="Solid" Skin="Silk" ToolTip="Código del Programa al que se asigna el gasto."
BorderWidth="1px" ReadOnly="false">
</telerik:RadTextBox>
<div style="left: 45px; position: absolute; top: 0px;">
<telerik:RadComboBox ID="cbProg" runat="server" RenderMode="Lightweight" EnableLoadOnDemand="true" Filter="StartsWith"
OnSelectedIndexChanged="cbProg_SelectedIndexChanged" AutoPostBack="true"
EmptyMessage="-- Select --" HighlightTemplatedItems="true" Skin="Metro" Width="230px" ToolTip="Nombre del programa al que se asigna el gasto.">
</telerik:RadComboBox>
<div style="left: 195px; position: absolute; top: 5px;">
<asp:RequiredFieldValidator ID="rfvPrograma" runat="server" ControlToValidate="cbProg"
ForeColor="Red" Font-Bold="true" SetFocusOnError="True" ValidationGroup="Guardar"></asp:RequiredFieldValidator>
</div>
<div style="left: 235px; position: absolute; top: 1px;">
<asp:ImageButton ID="btPrograma" runat="server" Text="" OnClick="btPrograma_Click"
ImageUrl="../Imagenes/find1.png" Width="24px" Height="24px" ></asp:ImageButton>
</div>
</div>
</div>
</div>
</td>
</tr>
//Method for list all programs of table in cbProg
public void ListarProgramas()
{
query = #"SELECT IdLinea, IdPrograma, Descripcion
FROM PRE_Programas";
cbComun(cbProg, query, "Descripcion", "IdLinea");
}
//Method for fill all comboBox
public void cbComun(RadComboBox cb, string str, string Texto, string Valor, int a=1 )
{
DataTable dt = dtSelec(str);
cb.Items.Clear();
cb.DataTextField = Texto;
cb.DataValueField = Valor;
cb.DataSource = dt;
cb.DataBind();
}
//Assigned Id Number of Program to other textbox filltering with SelectedValue of cbProg
protected void cbProg_SelectedIndexChanged(object sender, RadComboBoxSelectedIndexChangedEventArgs e)
{
query = #"SELECT IdLinea, IdPrograma, Descripcion FROM PRE_Programas WHERE IdLinea='" + cbProg.SelectedValue + "' ";
txtComun(txtProg, query, "IdPrograma");
}

Try binding the RadComboBox in the Page_Init event.

Related

Issue grabbing correct control/update panel in repeater

I'm having issues with dynamically updating a drop down list control when it is inside a repeater.
Basically I have a repeater and inside that repeater are 2 drop down lists. The one list is defined in my aspx page, the other drop down list is inside an update panel where I want to be able to have it dynamically update based on the selection of the first drop down list. I think part of my problem is the updatepanel is getting confused because I have more than one repeater item?
Here is the code for my repeater:
<asp:Repeater ID="billingTemplate" runat="server" OnItemDataBound="template_ItemDataBound">
<ItemTemplate>
<tr style="font-size: 100%" runat="server">
<td colspan="4" style="width: 100%; vertical-align: top">
<div class="panel panel-default panel-billing">
<asp:Panel CssClass="row panel-heading panel-heading-billing text-left" ID="headingBilling" ClientIDMode="Static" runat="server">
<div class="col-xs-1">
<input type="hidden" id="templateUK" runat="server" value='<%#Eval("templateUK")%>' />
</div>
<div class="col-sm-3">
<label for="ddlInvFilterType" class="col-sm-4 control-label text-right labelCls testclass">Filter Type:</label>
<div class="col-sm-8">
<asp:DropDownList runat="server" ID="ddlInvFilterType" ClientIDMode="Static" placeholder="Choose Filter Type" CssClass="form-control smallSize FilterType" AutoPostBack="true" OnSelectedIndexChanged="ddlFilterType_SelectedIndexChanged">
<asp:ListItem Value="">- None -</asp:ListItem>
<asp:ListItem Value="RevType1">Revenue Type 1</asp:ListItem>
<asp:ListItem Value="RevType2">Revenue Type 2</asp:ListItem>
<asp:ListItem Value="RevType3">Revenue Type 3</asp:ListItem>
<asp:ListItem Value="ServiceTeams">Service Team</asp:ListItem>
</asp:DropDownList>
</div>
</div>
<asp:UpdatePanel ID="InvFilterValuePanel" ClientIDMode="Static" runat="server" UpdateMode="Conditional" ChildrenAsTriggers="false">
<ContentTemplate>
<div class="col-sm-3">
<label for="ddlInvFilterValue" class="col-sm-4 control-label text-right labelCls">Filter Value:</label>
<div class="col-sm-8">
<asp:DropDownList runat="server" ID="ddlInvFilterValue" ClientIDMode="Static" placeholder="Choose Filter Value" CssClass="col-sm-6 form-control smallSize">
<asp:ListItem Value="">- None -</asp:ListItem>
</asp:DropDownList>
</div>
</div>
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="ddlInvFilterType" EventName="SelectedIndexChanged" />
</Triggers>
</asp:UpdatePanel>
</asp:Panel>
<asp:Panel CssClass="panel-collapse collapse" ID="collapseBilling" ClientIDMode="Static" runat="server">
<div class="panel-body">
<table class="table table-condensed table-bordered" style="margin: 0; padding: 0; border-top: none; border-bottom: none; border-left: thin; border-right: thin">
<tbody>
<%-- other controls --%>
</tbody>
</table>
</div>
</asp:Panel>
</div>
</td>
</tr>
</ItemTemplate>
</asp:Repeater>
Heres the code for my selected index change:
protected void ddlFilterType_SelectedIndexChanged(object sender, EventArgs e)
{
try
{
DropDownList ddl = (DropDownList)sender;
string ddlClass = ddl.CssClass;
string[] classes = ddlClass.Split(' ');
string repeaterClass = classes[classes.Length - 1];
string repeaterID = "0";
string appendStr = "";
if (repeaterClass.Contains("templateID"))
{
repeaterID = repeaterClass.Substring(repeaterClass.Length - 1);
appendStr = "_" + repeaterID;
}
foreach (RepeaterItem item in billingTemplate.Items)
{
HtmlInputHidden hidden = item.FindControl("headingBilling").FindControl("templateUK") as HtmlInputHidden;
if (hidden.Value == repeaterID)
{
DropDownList d1 = item.FindControl("headingBilling").FindControl("ddlInvFilterType") as DropDownList;
DropDownList d2 = item.FindControl("headingBilling").FindControl("ddlInvFilterValue") as DropDownList;
if (d1.SelectedValue.Length > 0)
{
d2.Items.Clear();
d2.Items.Add(new ListItem(" - None - ", ""));
switch (d1.SelectedValue)
{
case "ServiceTeams":
foreach (var pair in serviceTeamsController.GetAllServiceTeamsLOVs())
{
if (!String.IsNullOrWhiteSpace(pair.Value))
d2.Items.Add(new ListItem(pair.Value, pair.Key));
}
break;
default:
foreach (var pair in masterController.GetMasterLOVs(filterTypeDict[d1.SelectedValue]))
{
if (!String.IsNullOrWhiteSpace(pair.Value))
{
d2.Items.Add(new ListItem(pair.Value, pair.Key));
}
}
break;
}
}
else
{
d2.Items.Clear();
d2.Items.Add(new ListItem(" - None - ", ""));
}
}
}
}
catch (Exception ex)
{
}
}
Heres a screenshot of what I'm looking at when theres more than one repeater item:
Basically whats happening now is if I update the filter type in item2 it will update the filter value in item 1. If I update the filter type in item1 it will update the filter value in item 1 as expected.
What I want is to be able to update item2 filter type and then the filter value in item 2 is updated accordingly.
Anyone have any ideas on what I could be missing?
So ended up getting this to work, I think the main issue was the clientidmode was confusing the update panel somehow, so I removed that and made the update panel go around both drop downs. I also didnt end up needing the trigger so I removed that as well.

I need select single record in number of record importing

<asp:Panel ID="panelPriorYearImport" runat="server" Style="height: 200px; width: 450px;
border: 13px solid skyblue; display: none; background-color: Silver">
<div style="width: 80%; margin-left: 10%; margin-top: 25px;">
From which tax year you want to import vehicle information?
<br />
<asp:RadioButtonList ID="rbl_prior_yrs" runat="server" RepeatDirection="Horizontal">
<asp:ListItem Text="2014" Value="2014" Selected="True"></asp:ListItem>
<asp:ListItem Text="2013" Value="2013"></asp:ListItem>
<asp:ListItem Text="2012" Value="2012"></asp:ListItem>
</asp:RadioButtonList>
<br />
After importing you can edit or remove the vehicles.
<div style="text-align: center; padding-top: 25px;">
<asp:Button ID="btnPriorYrVehImport_Cancel" runat="server" CssClass="btnGray" Text="Cancel"
OnClick="btnPriorYrVehImport_Click" CausesValidation="false" Style="height: 30px;
width: 100px; margin-right: 20px;" />
<asp:Button ID="btnPriorYrVehImport" runat="server" CssClass="btnBlue" Text="Import"
OnClick="btnPriorYrVehImport_Click" CausesValidation="false" Style="height: 30px;
width: 100px" />
</div>
</div>
</asp:Panel>
above code is shows modal window. If click import button it will import the data. back end code is
Vehicle objVehicle = new Vehicle();
objVehicle.BusinessKey = Convert.ToString(Session["BUSINESS_KEY"]);
objVehicle.TaxYear = Convert.ToInt16(rbl_prior_yrs.SelectedItem.Value);
objVehicle.VehicleCategory = "T";
BAL_Vehicles objVehiclesOperation = new BAL_Vehicles();
DataTable ldtTaxableVeh = objVehiclesOperation.GetPriorYearVehicle(objVehicle);
#region TAXABLE VEHICLES FROM PRIOR YEAR FILING
try
{
if (ldtTaxableVeh == null)
CreateStructureTaxableVeh(ref ldtTaxableVeh);
else
{
ldtTaxableVeh.Columns["weight_current"].ColumnName = "weight_category";
ldtTaxableVeh.Columns["tax_amt"].ColumnName = "tax_amount";
ldtTaxableVeh.Columns.Add(new DataColumn("weight", typeof(string)));
foreach (DataRow ldr in ldtTaxableVeh.Rows)
ldr["weight"] = ddlWeight.Items.FindByValue(ldr["weight_category"].ToString()).Text;
}
ldtTaxableVeh.PrimaryKey = new DataColumn[] { ldtTaxableVeh.Columns["vin"] };
Session["TAX_AMOUNT"] = "0";
if (ldtTaxableVeh.Rows.Count > 0)
{
RecalculateAmount(ref ldtTaxableVeh);
foreach (DataRow ldr in ldtTaxableVeh.Rows)
Session["TAX_AMOUNT"] = Convert.ToDecimal(Session["TAX_AMOUNT"]) + Convert.ToDecimal(ldr["tax_amount"]);
}
}
catch { }
after importing number of data, i need select only one data please help

RadTextBox not updating

Hi I am trying to update some database values with a simple form with Telerik RadTextBoxes. I can set the text value no problem but when it comes to saving on button click the values do not get updated. My code to set the textbox is in the Page Load function however I am checking if(!IsPostBack)
Here is my html:
<div style="width:95%;">
<div style=" width:100%;float:left; background-color:#fff; border:1px solid #d1d2d3; margin-top:25px; padding:15px; -webkit-box-shadow: inset 1px 0px 5px 0px rgba(50, 50, 50, 0.10); -moz-box-shadow: inset 1px 0px 5px 0px rgba(50, 50, 50, 0.10); box-shadow: inset 1px 0px 5px 0px rgba(50, 50, 50, 0.10);">
<h2 style="float:left; width:50%;"><asp:Literal ID="litTitle" runat="server" Text="Add A New Zone" /></h2>
<telerik:RadAjaxPanel ID="RadAjaxPanel1" runat="server" Width="100%">
<telerik:RadNotification runat="server" id="notifyError" Position="Center" Width="330" Height="130" EnableRoundedCorners="true" EnableShadow="true" Style="z-index: 35000"></telerik:RadNotification>
<div style="float:right;margin-right:10px;margin-left:5px;"><telerik:RadButton ID="btnSave" runat="server" Text="Save" OnClick="btnSave_Click" /></div><div style="float:right;margin-right:5px;"><telerik:RadButton ID="btnCancel" runat="server" Text="Cancel" OnClick="btnCancel_Click" /></div><div style="float:right;margin-right:5px;"><telerik:RadButton ID="btnDelete" runat="server" Text="Delete" OnClick="btnDelete_Click" OnClientClicked="confirm('Are you sure you wish to delete this zone?');" /></div>
<div class="clear" style="clear:both;height:25px;"></div>
<div style="width:100%;">
<div style="float:left;">
<div style="float:left; margin-left:10px; margin-right:5px; width:200px;">Zone Code:</div>
<div style="float:left; margin-left:5px; margin-right:10px;"><telerik:RadTextBox ID="txtZoneName" runat="server" CausesValidation="false" Width="200"></telerik:RadTextBox></div>
</div>
<div class="clear" style="height:35px;clear:both;"></div>
<div style="float:left;">
<div style="float:left; margin-left:10px; margin-right:5px; width:200px;">Name:</div>
<div style="float:left; margin-left:5px; margin-right:10px;"><telerik:RadTextBox ID="txtZoneCode" runat="server" CausesValidation="false" Width="200"></telerik:RadTextBox></div>
</div>
<div class="clear" style="height:35px;clear:both;"></div>
<div>
<div style="float:left; margin-left:10px; margin-right:5px; width:200px;">Monthly Book Page Goal:</div>
<div style="float:left; margin-left:5px; margin-right:10px;"><telerik:RadTextBox ID="txtZoneBookGoal" runat="server" CausesValidation="false" Width="200"></telerik:RadTextBox></div>
</div>
<div class="clear" style="height:45px;clear:both;"></div>
<div style="width:250px; margin:0 auto;">
<div style="float:left;"><telerik:RadButton ID="btnCreate" runat="server" Text="Save" OnClick="btnCreate_Click" /></div>
</div>
</div>
</telerik:RadAjaxPanel>
</div>
</div>
Here is my c#:
protected void Page_Load(object sender, EventArgs e)
{
if(!Page.IsPostBack)
{
if(Request.Params["z"] != null)
{
Zones z = Zones.GetByID(Utils.GetLong(Request.Params["z"]));
this.txtZoneCode.Text = z.Code;
this.txtZoneName.Text = z.Name;
this.txtZoneBookGoal.Text = Utils.GetString(z.BookGoal);
this.litTitle.Text = "Edit Zone";
}
}
}
protected void btnSave_Click(object sender, EventArgs e)
{
bool valid = true;
string error = "";
if (this.txtZoneCode.Text == "")
{
valid = false;
error += "- Code<br/>";
}
if (this.txtZoneName.Text == "")
{
valid = false;
error += "- Name<br/>";
}
if (valid)
{
if (Request.Params["z"] != null)
{
Zones z = Zones.GetByID(Utils.GetLong(Request.Params["z"]));
z.Code = this.txtZoneCode.Text;
z.Name = this.txtZoneName.Text;
z.BookGoal = Utils.GetInt(this.txtZoneBookGoal.Text);
z.Save();
if (z.ZoneID > 0)
{
Response.Redirect("ManageZones.aspx?v=1", true);
}
else
{
this.notifyError.Title = "Zone update was not successfull!";
this.notifyError.Text = "There was an error saving your zone. Please try again";
this.notifyError.Show();
return;
}
}
else
{
Zones z = new Zones();
z.Code = this.txtZoneCode.Text;
z.Name = this.txtZoneName.Text;
z.BookGoal = Utils.GetInt(this.txtZoneBookGoal.Text);
z.Save();
if (z.ZoneID > 0)
{
Response.Redirect("ManageZones.aspx?v=1", true);
}
else
{
this.notifyError.Title = "Zone creation was not successfull!";
this.notifyError.Text = "There was an error saving your zone. Please try again";
this.notifyError.Show();
return;
}
}
}
else
{
this.notifyError.Title = "Please fill in the following to continue:";
this.notifyError.Text = error;
this.notifyError.Show();
return;
}
}
Robert Zeno
I changed OnClientClicked to OnClientClicking because there was a javascript error causing the page to break and not pull the correct data
You have four buttons - two buttons have same name Save.
Look like you are pressing the wrong. It makes me confuse too.
protected void btnSave_Click(object sender, EventArgs e)
{
// Not this event
}
protected void btnCreate_Click(object sender, EventArgs e)
{
// You need to use this event.
}
For better design practice
Use CSS instead of inline styles.
You need to name buttons properly. For example, SaveRadButton, CreateRadButton
DO NOT use Hungarian notation such as btnXXX especially when you use third party controls like telerik.

How to type data top to bottom (Top one should be new post and last one should be oldest one) asp.net c#

I am creating a social network website as facebook, but that website has some errors with posing status , i used following code to post status. I called this method on page_Load event and post button
private DataSet GetData()
{
string CS=ConfigurationManager.ConnectionStrings["RegistrationConnectionString"].ConnectionString;
using (SqlConnection con = new SqlConnection(CS))
{
SqlDataAdapter da = new SqlDataAdapter("Select * from PhotoStatusProfile WHERE Email = '" + Session["Email"].ToString() +"'",con);
DataSet ds = new DataSet();
da.Fill(ds);
return ds;
}
}
This is html code
<asp:Repeater runat="server" ID="Repeater1">
<ItemTemplate>
<div class="yourDivClass" style="border-top: thin none #BBCEB3; border-bottom: thin none #BBCEB3; padding: 10px; height: 121px; width: 548px; margin-top: 10px; right: 10px; left: 10px; border-left-width: thin; margin-left: 15px; background-color: #e9eaee; border-left-color: #BBCEB3; border-right-color: #BBCEB3;">
<br />
<div style="width: 58px; height: 62px">
<asp:Image ID="Image1" runat="server" Height="59px" ImageAlign="Top" ImageUrl="~/Profile/Image/supun_Profilemini.jpg" Width="55px" />
</div>
<div style="width: 307px; height: 21px; margin-left: 65px; margin-top: -60px">
<asp:Label ID="Label2" runat="server" Font-Bold="True" Font-Names="Arial" ForeColor="#000066" ><%#Eval("name") %> </asp:Label>
</div>
<div style="height: 22px; width: 461px; margin-left: 78px; margin-top: 11px"> <asp:Label ID="Label8" runat="server"><%#Eval("Status") %></asp:Label>
<br><br>
</div>
</div>
</ItemTemplate>
post button cs code
protected void Post_Click(object sender, EventArgs e)
{
SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["RegistrationConnectionString"].ConnectionString);
conn.Open();
try
{
string inserQuery = "insert into PhotoStatusProfile(Name,Status,Email) values (#Name,#Status,#e)";
SqlCommand commm = new SqlCommand(inserQuery, conn);
commm.Parameters.AddWithValue("#Name", ProfileName.Text);
commm.Parameters.AddWithValue("#Status",TextBox1.Text);
commm.Parameters.AddWithValue("#e", Label1.Text);
commm.ExecuteNonQuery();
Label1.Text = Session["Email"].ToString();
}
catch (Exception ex)
{
Response.Write("Error -->" + ex.ToString());
conn.Close();
}
// LoadData();
Repeater1.DataSource = GetData();
Repeater1.DataBind();
TextBox1.Text = "";
}
But After i'm posting some status I faced some errors.
1,On this website, my new post displayed on bottom and oldest one on top but i want new post to top and others Gradually top to bottom ,(descending order by considering time)
when i posted big status, it will display Like this.
I want to fix this also.
Thanks
You should think about storing some kind of date for each post. Then you can get a sorted list from the database. Something like this:
SqlDataAdapter da = new SqlDataAdapter("Select * from PhotoStatusProfile WHERE Email = '" + Session["Email"].ToString() +" order by CreatedAt desc'",con);
This would also allow you to show a "posted"-Date, show posts by day/week/month etc.
Reversing Repeater order
To make a long word wrap you can apply css:
word-wrap: break-word;

accessing checkbox inside listview?

i have a group of listviews with a checkbox in each listview as:
<telerik:RadListView Skin="Vista" ID="RadListView3" DataSourceID="SqlDataSource_subentry"
runat="server" ItemPlaceholderID="EmployeesContainer" DataKeyNames="ID">
<LayoutTemplate>
<fieldset id="FieldSet1">
<legend>Issues</legend>
<asp:PlaceHolder ID="EmployeesContainer" runat="server" ></asp:PlaceHolder>
<br />
<br />
</fieldset>
</LayoutTemplate>
<ItemTemplate>
<div style="width:200px; height:165px; -webkit-border-radius: 20px;-moz-border-radius: 20px; border-radius: 20px;
border:2px solid black; background-color:#00FFFF; text-align:center; margin-top:20px; margin-bottom:10px;
margin-left:20px; ">
<br />
<div style=" width:190px; height:auto; font-size:small;color:#000099; text-align:left; margin-left:12px;"><%#Eval("Worked_Project")%>
<label id="Label1" runat="server"><%# Eval( "ID" ) %></label>
<asp:CheckBox ID="MyCheckBox" runat="server" Text=<%# Eval( "ID" ) %>/></div>
<div style="width:190px; height:auto; font-size:small;color:black;text-align:center; padding-left:2px; margin-left:5px;" ><%# DataBinder.Eval(Container.DataItem, "Week_Ending", "{0:d/M/yyyy }")%></div>
<div style=" width:190px; height:75px; font-size:large; color:#000099; text-align:center; "><%#Eval("Activity")%> </div>
<div style=" width:190px; height:auto; font-size:small;color:black; text-align:left; margin-left:12px; margin-bottom:5px; "><%#Eval("UserId")%> </div>
</div>
</ItemTemplate>
on a button click i want to pick the id assocaiated with a particular checkbox as:
protected void Button1_Click(object sender, EventArgs e)
{
foreach (Control ctl in RadListView3.Controls)
{
CheckBox chk = (CheckBox)ctl.FindControl("MyCheckBox");
if (chk.Checked== true)
{
string value = chk.Text.ToString();
Session["id"] = value.ToString();
Label2.Text = Session["id"].ToString();
}
}
}
but it is giving error on line of code:
if (chk.Checked== true)
and the error is
Object reference not set to an instance of an object.
plzz help me out
Try this:
protected void RadListView1_ItemCommand(object sender,Telerik.Web.UI.RadListViewCommandEventArgs e)
{
CheckBox button = (CheckBox)e.ListViewItem.FindControl("CheckBox1");
if (e.CommandName == "Approve")
{
if (button.Checked == true)
{
//your code
}
else
{
//your code
}
}
}
or if you need to pick id on Button click only (loop) follow below link.
http://www.telerik.com/community/forums/aspnet-ajax/listview/get-selected-value-of-radlistview.aspx
You have to check type of this control first
CheckBox chk = ctl as CheckBox ;
if (chk !=null)
{
//do something
}
more info. about as
keyword

Categories

Resources