asp DropDownList inside ListView with UpdatePanel. SelectedIndexChanged Not fire when select item from dropdownlist.
Already Tryied Every Solution.
OnPageLoad()
!isPost
AutoPostBack="True"
ViewStateMode="Enabled"
EnableViewState="true"
<asp:ListView ID="productListView" runat="server" OnItemDataBound="productListView_ItemDataBound">
<ItemTemplate>
<div class="item col-lg-3 col-md-4 col-sm-6 col-xs-12">
<div class="hovereffect">
<div class="overlay">
<div class="selection">
<asp:Label runat="server" CssClass="lblShowTag">BRAND:</asp:Label>
<asp:DropDownList ID="ddlBrand" runat="server" CssClass="branddrop" AutoPostBack="True" OnSelectedIndexChanged="ddlBrand_SelectedIndexChanged" ViewStateMode="Enabled" EnableViewState="true">
</asp:DropDownList>
<asp:UpdatePanel ID="updatePanel" runat="server" >
<ContentTemplate>
<asp:Label runat="server" ID="lblShowTag" text="PRICE: " CssClass="lblShowTag"/><asp:Label runat="server" ID="lblEachPrice" CssClass="lblEachPrice"/>
<div class="clearfix"></div>
<asp:Label runat="server" class="lblShowTag">QUANTITY: </asp:Label>
<asp:TextBox ID="txtQuantity" runat="server" Text="1" CssClass='txtquantity' />
<div class="clearfix"></div>
<asp:Label runat="server" ID="Label1" text="TOTAL: " CssClass="lblShowTag"/><asp:Label runat="server" ID="lblTotalPrice" CssClass="lblEachPrice" ForeColor="Green" Text="5000"/>
<div class="clearfix"></div>
<asp:Label id="lblError" runat="server" Text="Label 2" ForeColor="Red"/>
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="ddlBrand" EventName="SelectedIndexChanged" />
</Triggers>
</asp:UpdatePanel>
</div>
</div>
</div>
</div>
</ItemTemplate>
<EmptyDataTemplate>
<h3>Sorry...No Product Availabel</h3>
</EmptyDataTemplate>
</asp:ListView>
C# Code:
protected void Page_Load(object sender, EventArgs e)
{
//showProdutListView();
String CateId = Request.QueryString["CateId"];
if (!String.IsNullOrEmpty(CateId))
{
showProdutListView(CateId);
}
else
{
Response.Redirect("/default.aspx");
}
if (!IsPostBack)
{
if (Session["myCart"] != null)
{
DataTable dt = (DataTable)Session["myCart"];
cartQuantity = dt.Rows.Count.ToString();
}
else
{
cartQuantity = "0";
}
((ProdutcPageNested)Master).OnProductMasterPage.Text = "Cart Items: " + cartQuantity;
ShowBrand();
}
}public void ddlBrand_SelectedIndexChanged(object sender, EventArgs e)
{
foreach (ListViewItem item in productListView.Items)
{
DropDownList ddl = (DropDownList)sender;
lblEachPrice.Text = ddl.SelectedValue.ToString();
}
}
The problem here is you are binding data on page load, so whenever DDL is posting page loads new values causing not to fire OnSelectdIndedChanged event. Here is my solution hope it works.
this should be replaced
if (!String.IsNullOrEmpty(CateId))
{
showProdutListView(CateId);
}
else
{
Response.Redirect("/default.aspx");
}
if (!IsPostBack)
{
if (Session["myCart"] != null)
{
DataTable dt = (DataTable)Session["myCart"];
cartQuantity = dt.Rows.Count.ToString();
}
else
{
cartQuantity = "0";
}
((ProdutcPageNested)Master).OnProductMasterPage.Text = "Cart Items: " + cartQuantity;
ShowBrand();
}
with this
if (!IsPostBack)
{
if (!String.IsNullOrEmpty(CateId))
{
showProdutListView(CateId);
}
else
{
Response.Redirect("/default.aspx");
}
if (Session["myCart"] != null)
{
DataTable dt = (DataTable)Session["myCart"];
cartQuantity = dt.Rows.Count.ToString();
}
else
{
cartQuantity = "0";
}
((ProdutcPageNested)Master).OnProductMasterPage.Text = "Cart Items: " + cartQuantity;
ShowBrand();
}
Related
i want to show the panel 'keuze' if i click one of the radio buttons.
This is the code i have sofar, i am already trying over a hour to get it working. But i really cant find the solution so if someone could help i would really appreciate that.
<div id="object" style="position:absolute; top:300px;">
<label>Kies een object:</label>
<br />
<asp:RadioButtonList ID="rblObject" runat="server" Height="52px" OnSelectedIndexChanged="rblObject_SelectedIndexChanged">
<asp:ListItem Value="rblVloer">Vloer</asp:ListItem>
<asp:ListItem Value="rblKamer">Kamer</asp:ListItem>
</asp:RadioButtonList>
</div>
<asp:Panel ID="keuze" runat="server" style="position:absolute; top:400px;">
<asp:Label ID="Label2" runat="server" Text="Maak je keuze:"></asp:Label>
<asp:RadioButtonList ID="RadioButtonList2" runat="server">
<asp:ListItem Value="rblVierkant">Vierkant</asp:ListItem>
<asp:ListItem Value="rblKubus">Kubus</asp:ListItem>
</asp:RadioButtonList>
</asp:Panel>
Ander here is the code of the radiobuttons
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
keuze.Visible = false;
}
protected void rblObject_SelectedIndexChanged(object sender, EventArgs e)
{
if(rblObject.SelectedItem.Value == "rblVloer")
{
keuze.Visible = true;
}
}
}
Thanks for your time!
I think you need some thing like this .I have done it by jQuery
<script src="../js/jquery.js" type="text/javascript"></script>
<script type="text/javascript">
$(function () {
$('#rblObject input').click(function () {
var selectedValue = $("#rblObject input:radio:checked").val();
alert('Selected Value: ' + selectedValue);
if (selectedValue == "rblVloer") {
$("#keuze").css({ display: "none" });
} else {
$("#keuze").css({ display: "" });
}
});
});
</script>
and
<div id="object" style="position:absolute; top:300px;">
<label>Kies een object:</label>
<br />
OnSelectedIndexChanged="rblObject_SelectedIndexChanged"
<asp:RadioButtonList ID="rblObject" runat="server" Height="52px" ClientIDMode="Static">
<asp:ListItem Value="rblVloer">Vloer</asp:ListItem>
<asp:ListItem Value="rblKamer">Kamer</asp:ListItem>
</asp:RadioButtonList>
</div>
<asp:Panel ID="keuze" runat="server" style="position:absolute; top:400px;" ClientIDMode="Static">
<asp:Label ID="Label2" runat="server" Text="Maak je keuze:"></asp:Label>
<asp:RadioButtonList ID="RadioButtonList2" runat="server">
<asp:ListItem Value="rblVierkant">Vierkant</asp:ListItem>
<asp:ListItem Value="rblKubus">Kubus</asp:ListItem>
</asp:RadioButtonList>
</asp:Panel>
Note: no need to postback
ClientIDMode="Static"
is necessary to get exact id of Control.
And make sure jQuery is loaded to perform this.
Im write code for Drop down list selected value add the the list box and text filed , i can remove the list box value but cant remove the text filed value, please how to write code remove the same adding value for text filed and list box
Im add the dropdownlist value AA, Its display list box and text box, but click the remove button always removed selected List Box item but not remove text box value
<div class="col-sm-3">
<asp:TextBox ID="txtQlt" runat="server" CssClass="form-control" Width="348px" OnTextChanged="txtQlt_TextChanged" ReadOnly="true"></asp:TextBox>
</div><div class="col-md-1" style="margin-left:115px;">
<asp:Label ID="Label4" runat="server" ForeColor="Red" Text="*" ></asp:Label>
</div>
</div>
<br />
<div class="row">
<div class="col-sm-2">
<asp:Label ID="Label6" runat="server" Text="Quality reference" Font-Bold="True" Font-Names="arial, helvetica, sans-serif" Font-Size="13px"></asp:Label>
</div>
<div class="col-sm-3">
<asp:DropDownList ID ="cmbQualityRef" runat ="server" CssClass="form-control" Width="250px" >
</asp:DropDownList>
<asp:ListBox ID="lstValue" runat="server" CssClass="content" Rows="5" ValidationGroup="save"
Width="250" ></asp:ListBox>
</div>
<asp:ImageButton ID="btnAdd" runat="server" CssClass="button" Text="Add" ValidationGroup="add"
OnClick="btnAdd_Click" ImageUrl="~/img/Add.png"/>
<asp:ImageButton ID="btnImageRemove" runat="server" OnClick="btnImageRemove_Click"
ImageUrl="~/img/Remove.png" />
<div class="col-md-1" style="margin-left:16px;">
<asp:Label ID="Label7" runat="server" ForeColor="Red" Text="*" ></asp:Label>
</div>
</div>
protected void btnAdd_Click(object sender, EventArgs e)
{
AddToList();
lstValue.Items.Remove("");
}
--------------------------------------------
private void AddToList()
{
if (lstValue.Items.FindByText(cmbQualityRef.SelectedItem.ToString()) == null)
{
if (lstValue.Items.Count > 0)
{
txtQlt.Text = txtQlt.Text + "," + cmbQualityRef.SelectedItem.ToString();
}
else
{
txtQlt.Text = cmbQualityRef.SelectedItem.ToString();
}
ListItem itm = new ListItem();
itm.Value = cmbQualityRef.SelectedValue;
itm.Text = cmbQualityRef.SelectedItem.ToString();
lblMsg.Text = "";
lstValue.Items.Add(itm);
}
else
{
lblMsg.Text = "Selected Item Already Exists In The List.";
lblMsg.ForeColor = System.Drawing.Color.Red;
}
}
protected void btnImageRemove_Click(object sender, ImageClickEventArgs e)
{
try
{
if (lstValue.SelectedItem != null)
{
lstValue.Items.Remove(lstValue.SelectedItem);
txtQlt.Text = txtQlt.Text.Replace(lstValue.SelectedItem.ToString(), "").Trim();
}
}
catch (Exception)
{
}
}
You should remove item from list after replacing the string,other wise it can't find the item from list.
Your code looks like:
protected void btnRemove_Click(object sender, EventArgs e)
{
try
{
if (lst.SelectedItem != null)
{
txt.Text = txt.Text.Replace(lst.SelectedItem.ToString(), "").Trim();
lst.Items.Remove(lst.SelectedItem);
}
}
catch (Exception)
{
}
}
I need to assign a value of linkbutton selected from datalist to a label.
How can i do this?
.aspx code
<asp:DataList ID="DataList1" runat="server" DataSourceID="SqlDataSource1"
style="margin-left: 5px"
onselectedindexchanged="DataList1_SelectedIndexChanged">
<ItemTemplate>
<asp:LinkButton ID="LinkButton2" runat="server" Text='<%# Eval("Description") %>' Font-Underline="False" ForeColor="Black" Font-Italic="False" ToolTip="click to open"></asp:LinkButton>
<br />
</ItemTemplate>
</asp:DataList>
<br />
<asp:Label ID="item" runat="server" Text="Label"></asp:Label>
.aspx.cs
protected void DataList1_SelectedIndexChanged(object sender, EventArgs e)
{
item.Text = DataList1.SelectedIndex.ToString();
}
this can be done like this :
<asp:Label1 ID="Label1" runat="server"
Text='<%# Bind("your datafield") %>'
Try the following:
protected void DataList1_SelectedIndexChanged(object sender, EventArgs e)
{
var myLink = DataList1.SelectedItem.FindControl("LinkButton2") as LinkButton;
if (myLink != null)
{
item.Text = myLink.Text;
}
}
In web application, How can i display current month calender in gridview, i mean calender dates as a columns. can you please tell me how can i start the coding or is there any reference. Thank you.
Display calendar in gridview using c# Asp.net
Using client side code:
<div class="col-lg-12 col-md-12 col-sm-12" style="padding-right: 15px;">
<div class="row panel panel-default" style="margin-bottom: 5px; padding: 10px; border-radius: 4px; border: 1px solid #c5c5c5; background: #f5f5f5;">
<div class="col-lg-12 col-md-12 col-sm-12 col-xs-12" style="padding: 0px;">
<div class="col-lg-12 col-md-12 col-sm-12 col-xs-12 table-responsive" style="padding-bottom: 5px;">
<div class="col-md-1">
<label style="font-size: medium;">Month</label>
<asp:DropDownList ID="drpMonth" runat="server"
ClientIDMode="Static" CssClass="chart-type form-control" Style="font-size: 14px;">
<asp:ListItem Text="Jan" Value="1"></asp:ListItem>
<asp:ListItem Text="Feb" Value="2"></asp:ListItem>
<asp:ListItem Text="Mar" Value="3"></asp:ListItem>
<asp:ListItem Text="Apr" Value="4"></asp:ListItem>
<asp:ListItem Text="May" Value="5"></asp:ListItem>
<asp:ListItem Text="Jun" Value="6"></asp:ListItem>
<asp:ListItem Text="Jul" Value="7"></asp:ListItem>
<asp:ListItem Text="Aug" Value="8"></asp:ListItem>
<asp:ListItem Text="Sep" Value="9"></asp:ListItem>
<asp:ListItem Text="Oct" Value="10"></asp:ListItem>
<asp:ListItem Text="Nov" Value="11"></asp:ListItem>
<asp:ListItem Text="Dec" Value="12"></asp:ListItem>
</asp:DropDownList>
</div>
<div class="col-md-1">
<label style="font-size: medium;">Year</label>
<asp:DropDownList ID="drpYear" runat="server"
ClientIDMode="Static" CssClass="chart-type form-control" Style="font-size: 14px; padding: 6px 10px;">
</asp:DropDownList>
</div>
<div class="col-md-2 dv-appointment">
<label style="color: #f5f5f5;">retrieve button text</label>
<asp:Button runat="server" ID="btnRetrieve" OnClick="btnRetrieve_Click" CssClass="btn btn-success" Text="Retrieve" />
</div>
</div>
</div>
<div class="col-lg-12 col-md-12 col-sm-12 col-xs-12" style="text-align: center;">
<label title="" style="font-size: 18px !important; font-weight: 300 !important; color: #f12f2f;">
<%--Click on date to schedule a new appointment--%>
**Select date on the calendar to create a new appointment
</label>
</div>
<asp:Calendar DayStyle-Height="68px" ID="clAppointment" OnDayRender="clAppointment_DayRender"
runat="server" BackColor="#f1fbf0" BorderColor="#999999" BorderWidth="1px" DayNameFormat="Short" NextPrevStyle-ForeColor="#FFFFFF" NextPrevStyle-CssClass="pd-left-right"
names="Verdana" size="20pt" ForeColor="#484848" Height="100%" ShowGridLines="True"
Width="100%" Font-Bold="True" Font-Size="Medium" FirstDayOfWeek="Sunday">
<SelectedDayStyle BackColor="#CCCCFF"></SelectedDayStyle>
<SelectorStyle BackColor="#FFCC66"></SelectorStyle>
<TodayDayStyle ForeColor="#FF6600" BackColor="#bce0cc"></TodayDayStyle>
<OtherMonthDayStyle ForeColor="#d2a87e82"></OtherMonthDayStyle>
<%--#CC9966--%>
<DayHeaderStyle BackColor="#bce4ab" CssClass="text-center" Height="3px" Font-Bold="True" Font-Size="Medium"></DayHeaderStyle>
<TitleStyle BackColor="#666666" Font-Size="Medium" ForeColor="White" Font-Bold="True" Height="8.8px"></TitleStyle>
</asp:Calendar>
</div>
</div>
Using server side Code:
using System;
using System.Data;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace Commerce.Clinics
{
public partial class Appointment_Calendar : BaseClass
{
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
int CurrentYear = DateTime.Now.Year;
drpMonth.SelectedValue = DateTime.Now.Month.ToString();
drpYear.Items.Add(new ListItem(Convert.ToString(CurrentYear - 1), Convert.ToString(CurrentYear - 1)));
drpYear.Items.Add(new ListItem(Convert.ToString(CurrentYear), Convert.ToString(CurrentYear)));
drpYear.Items.Add(new ListItem(Convert.ToString(CurrentYear + 1), Convert.ToString(CurrentYear + 1)));
drpYear.SelectedValue = Convert.ToString(CurrentYear);
string strMinDate = Convert.ToInt32(drpMonth.SelectedValue) + "/" + "01/" + Convert.ToString(CurrentYear);
string strMaxDate = Convert.ToInt32(drpMonth.SelectedValue) + "/" + DateTime.DaysInMonth(CurrentYear, Convert.ToInt32(drpMonth.SelectedValue)) + "/" + Convert.ToString(CurrentYear);
Session["ScheduleDate"] = GetBookedAppointmentByClinic(strMinDate, strMaxDate);
}
}
protected void clAppointment_DayRender(object sender, DayRenderEventArgs x)
{
int ApptBooked = 0;
string booked = "", booked1 = "";
TableCell cell = (TableCell)x.Cell;
if (Convert.ToInt32(SessionFactory.CurrentUser.LocationId) != 0)
{
x.Day.IsSelectable = false;
CalendarDay day = (CalendarDay)x.Day;
DataTable dtbooked = (DataTable)Session["ScheduleDate"];
DataRow[] drSelect = dtbooked.Select("apptdate='" + day.Date.ToString("MM/dd/yyyy") + "'");
if (drSelect.Length > 0)
{
ApptBooked = Convert.ToInt32(drSelect[0]["apptcount"]);
}
if (ApptBooked > 0)
{
booked = "<font color='#b53737'>";
booked1 = "</font>";
}
if (day.IsOtherMonth)
{
x.Cell.Text = "";
x.Cell.BackColor = System.Drawing.Color.White;
}
//else if (day.Date.ToString("dddd") == "Saturday" || day.Date.ToString("dddd") == "Sunday")
//{
// cell.BackColor = System.Drawing.Color.White;
//}
// Bind Booked appotionment for spacific location and department.
//else if (ucLocationDept.LocationId != "0" && ucLocationDept.DepartmentId != "0")
//{
else if (day.Date < DateTime.Today.Date && ApptBooked == 0)
{
}
else
{
cell.Controls.Add(new LiteralControl("<br/><a class='schedlnk' style='font-size:medium;color:green;cursor:pointer;' href=EmployeeAppointment.aspx?date=" + day.Date.ToString("MM/dd/yyyy") + ">" + booked + +ApptBooked + " Booked " + booked1 + "</a>"));
}
/*}
else
{
cell.Controls.Add(new LiteralControl("<br/><a class='schedlnk' style='font-size:medium;color:green;cursor:pointer;'>" + booked + ApptBooked + " Booked" + booked1 + "</a>"));
}*/
}
}
public DataTable GetBookedAppointmentByClinic(string StartDate, string EndDate)
{
SqlParameter[] PM = new SqlParameter[]
{
new SqlParameter("#Mode", "Mode_Name"),
new SqlParameter("#StartDate", StartDate),
new SqlParameter("#EndDate", EndDate),
new SqlParameter("#LocationId", Convert.ToInt32(SessionFactory.CurrentUser.LocationId)),
};
DataTable dt = SqlHelper.ExecuteDataset(new SqlConnection(SqlHelper.GetConnectionString()), CommandType.StoredProcedure, "ProcName", PM).Tables[0];
return dt;
}
#endregion
protected void btnRetrieve_Click(object sender, EventArgs e)
{
clAppointment.SelectedDates.Clear();
clAppointment.VisibleDate = new DateTime(Convert.ToInt32(drpYear.SelectedValue), Convert.ToInt32(drpMonth.SelectedValue), 1);
string strMinDate = Convert.ToString(drpYear.SelectedValue) + "-" + Convert.ToString(drpMonth.SelectedValue) + "-01";
string strMaxDate = Convert.ToString(drpYear.SelectedValue) + "-" + Convert.ToString(drpMonth.SelectedValue) + "-" + DateTime.DaysInMonth(Convert.ToInt32(drpYear.SelectedValue), Convert.ToInt32(drpMonth.SelectedValue));
Session["ScheduleDate"] = GetBookedAppointmentByClinic(strMinDate, strMaxDate);
}
}
}
add a TemplateField to your GridView and insert a calendar to the TemplateField, like this:
<asp:GridView ID="GridView1" runat="server" DataSourceID="ObjectDataSource1" >
<Columns>
<asp:TemplateField>
<ItemTemplate>
<asp:Calendar ID="Calendar2" runat="server"></asp:Calendar>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
I develop user control based on repeater. It must contains predefined checkBox for each row.
Any suggestions?
Perhaps, something like this?
Default.aspx
<%# Page Language="C#" %>
<script runat="server">
protected override void CreateChildControls()
{
base.CreateChildControls();
LoadUserControl();
}
private void LoadUserControl()
{
ph.Controls.Clear();
Control c = LoadControl("~/WebUserControl.ascx");
c.ID = "foo";
ph.Controls.Add(c);
}
</script>
<html>
<body>
<form id="form1" runat="server">
<div>
<asp:PlaceHolder ID="ph" runat="server" />
</div>
<asp:Button runat="server" />
</form>
</body>
</html>
WebUserControl.ascx
<%# Control Language="C#" %>
<%# Import Namespace="System.Data" %>
<script runat="server">
protected override void OnLoad(EventArgs e)
{
base.OnLoad(e);
if (!IsPostBack)
{
DataTable dt = GetRawDataTable();
dt.Rows.Add(dt.NewRow());
rpt.DataSource = dt;
rpt.DataBind();
}
}
private static DataTable GetRawDataTable()
{
DataTable dt = new DataTable();
dt.Columns.Add(new DataColumn("product", typeof(string)));
dt.Columns.Add(new DataColumn("checked", typeof(bool), "false"));
return dt;
}
protected void OnBtnAddClicked(object sender, EventArgs e)
{
DataTable dt = GetRawDataTable();
foreach (RepeaterItem ri in rpt.Items)
{
TransferFromPage(ri, dt);
}
dt.Rows.Add(dt.NewRow());
rpt.DataSource = dt;
rpt.DataBind();
}
private static void TransferFromPage(RepeaterItem ri, DataTable dt)
{
DataRow row = dt.NewRow();
row["product"] = ((TextBox)ri.FindControl("txtProduct")).Text;
row["checked"] = ((CheckBox) ri.FindControl("chk")).Checked;
dt.Rows.Add(row);
}
protected void OnRptItemCmd(object sender, RepeaterCommandEventArgs ea)
{
switch (ea.CommandName)
{
case "RemoveRow":
DataTable dt = GetRawDataTable();
foreach (RepeaterItem ri in rpt.Items)
{
if (ri.ItemIndex == ea.Item.ItemIndex) continue;
TransferFromPage(ri, dt);
}
rpt.DataSource = dt;
rpt.DataBind();
break;
}
}
</script>
<div>
<table>
<asp:Repeater ID="rpt" runat="server" OnItemCommand="OnRptItemCmd">
<ItemTemplate>
<tr>
<td>
<asp:TextBox ID="txtProduct" runat="server" Text='<%# Eval("product") %>' />
<asp:CheckBox ID="chk" runat="server" Checked='<%# Eval("checked") %>' />
<asp:Button ID="btnRemove" runat="server" Text="-" CommandName="RemoveRow" />
</td>
</tr>
</ItemTemplate>
<FooterTemplate>
<tr>
<td>
<asp:Button ID="btnAdd" runat="server" Text="+" OnClick="OnBtnAddClicked" />
</td>
</tr>
</FooterTemplate>
</asp:Repeater>
</table>
</div>
you can use the Repeater's ItemTemplate, to put necessary controls. Below is an example:
<asp: Repeater>
<ItemTemplate>
<asp:CheckBox ID="cbkWhatever" runat="server" Checked='<%# Eval("CbkDataField") %>' />
All other items for Repeater ...
</ItemTemplate>
</asp:Repeater>