Get data from from repeater via Request.Form to another page - c#

I have a simple repeater to list textbox.
try.aspx
<form id="form1" runat="server" action="try_send.aspx" method="get">
<div>
<asp:Repeater ID="ClRpt" runat="server">
<HeaderTemplate>
</HeaderTemplate>
<ItemTemplate>
<asp:Label ID="Kod" runat="server" Text='<%#Eval("KOD") %>'></asp:Label>
<asp:TextBox ID="Amount" runat="server"></asp:TextBox>
<asp:Button ID="ButtonClick" CssClass="bt" runat="server" Text="SEPETE EKLE" Width="100%" UseSubmitBehavior="false" />
</ItemTemplate>
</asp:Repeater>
</div>
</form>
try.aspx.cs:
protected void Page_Load(object sender, EventArgs e)
{
string Firma = Session["FirmaID"].ToString();
string Pryt = "01";
string GRID = "KATALOG";
Page.Title = GRID + " ÜRÜN LİSTESİ";
string SQLGrup = "SQL Here";
SqlCommand rsCl = new SqlCommand(SQLGrup, bag.Bagla());
SqlDataReader ClOku = rsCl.ExecuteReader();
ClRpt.DataSource = ClOku;
ClRpt.DataBind();
ClOku.Close();
}
I want to send textbox value named Amount to try_send.aspx file
try_send.aspx:
<body>
<asp:Label ID="Amount" runat="server" Text="Label"></asp:Label>
</body>
try_send.aspx.cs:
protected void Page_Load(object sender, EventArgs e)
{
decimal Amnt = Convert.ToDecimal(Request.Form["Amount"]);
Amount.Text = Amnt.ToString();
}
Amount is null when I send the form.
Thanks...

In try.aspx, you just show a bunch of information in your Repeater.
You don't have a button to submit the action.
<form id="form1" runat="server">
<asp:Repeater ID="ClRpt" runat="server">
//content
</asp:Repeater>
<asp:Button Id="xx" runat="server" OnClick="xx_OnClick"/>
</form>
Then, you redirect and pass the amount you want in the event click
public void xx_Onclick(object sender, EventArgs e)
{
//redirect to try_send with the value amount
}

Related

"Add To Cart" Button in DataList ASP.NET

I Need to Add a button Add To Cart in Data-list.
The problem is, When i Click on btn ADD Button, Datalist1_ItemCommand() is never reached, but a Postback event occurs
I need to Add a Button that reads the current item values & performs some operations on it.
ASP Code
<asp:DataList ID="DL_Products" runat="server" RepeatColumns="3" OnItemCommand="Datalist1_ItemCommand">
<ItemTemplate>
<div class="Item">
<div class="title">
<asp:Label ID="lbl_Brand" runat="server" Text='<%# Eval("Brand") %>'></asp:Label>
</div>
<div class="Info">
Price/Piece :
<asp:Label ID="lbl_Price" runat="server" Text='<%# Eval("Price") %>'></asp:Label>
Rs
<br />
<asp:Button ID="btn" CommandName="AddtoCart" runat="server" Text="Add" />
</div>
</div>
</ItemTemplate>
</asp:DataList>
C#/ Code Behind :
protected void Datalist1_ItemCommand(object source, DataListCommandEventArgs e)
{
if (e.CommandName == "AddtoCart")
{
Label l1 = (Label)e.Item.FindControl("lbl_Price");
string a = l1.Text;
Response.Write(l1.Text);
}
}
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
load_User_data();
Brand_SelectedIndexChanged(null, null);
load_data();
}
}
add if(!ispostback){ bind datalist} on page load

how to find checkbox where checked in repeater in asp.net?

i want when click btndelete , every checkbox where chechek in repeater1 to get value of column(titr) in same row, but i dont find which checkbox checked and dont access to value of column(titr)
<asp:Repeater ID="Repeater1" runat="server">
<HeaderTemplate>
<table>
<tr>
<td> </td>
<td>subject</td>
</tr>
</HeaderTemplate>
<ItemTemplate>
<tr>
<td>
<asp:CheckBox ID="CheckBox1" runat="server" />
</td>
<td id="checkvalue" >
<%# Eval("titr") %>
</td>
</tr>
</ItemTemplate>
<FooterTemplate></table></FooterTemplate>
</asp:Repeater>
<asp:Button ID="btndelete" runat="server" Text="delete" OnClick="btndelete_Click" />
.cs code is :
protected void btndelete_Click(object sender, EventArgs e)
{
}
You could get a list of repeaterItems for each row in which the checkbox is checked using linq such that:
List<RepeaterItem> selectedItems = Repeater1.Items.Cast<RepeaterItem>().Where(x => ((CheckBox)x.FindControl("CheckBox1"))
.Checked).ToList();
You could then iterate through the list and get the value of titr for each of the selected rows, but you would have to set some server control equal to "titr" when you bind the control, like:
<asp:literal id="literal1" runat="server"><%# Eval("titr") %></asp:literal>
That way you could go find the value later when you iterate through the list, like this:
List<string> titrValues = selectedItems.Select(t => ((Literal)t.FindControl("literal1).Text));
You may have to do some tweaking, but that should get you the values of titr for each row with a selected value.
Aspx Code:
<%# Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<asp:Repeater ID="Repeater1" runat="server" >
<ItemTemplate>
<div>
<asp:CheckBox ID="CategoryID" runat="server" Text='<%# Eval("val") %>' />
</div>
</ItemTemplate>
</asp:Repeater>
<asp:Button Text="Click" OnClick="Button2_Click" runat="server" />
</form>
</body>
</html>
CS Code:
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
DataTable dt = new DataTable();
dt.Columns.Add("val", typeof(string));
for (int i = 0; i < 10; i++)
dt.Rows.Add("testing" + i.ToString());
Repeater1.DataSource = dt;
Repeater1.DataBind();
}
}
protected void Button2_Click(object sender, EventArgs e)
{
string Rpt = "Repeater Items Checked:<br />";
for (int i = 0; i < Repeater1.Items.Count; i++)
{
CheckBox chk = (CheckBox)Repeater1.Items[i].FindControl("CategoryID");
if (chk.Checked)
{
Rpt += (chk.Text + "<br />");
}
}
Response.Write(Rpt);
}
You can also use break point to check the get values....
Refrenced By: http://www.codeproject.com/Questions/534719/GetplusSelectedplusCheckboxesplusinplusASPplusRepe

Form not rendering updated label after postback

I have been have problems with a postback from the button submit as after the button has finished the site think its a full refresh which gives me no chance to show any failure of login message or error,
I cant seem to pinpoint why this is happening and have looked up about the page cycle but can't put my finger on it.
Heres all my code for behind the page
protected void Page_Init(object sender, EventArgs e)
{
Session["user"] = "";
Session["domain"] = "";
Session["manager"] = "";
}
protected void Page_Load(object sender, EventArgs e)
{
if (Page.IsPostBack)
lblError.Text = "This was a post back.";
else
lblError.Text = "This was NOT a post back.";
}
protected void btnLogin_Click(object sender, EventArgs e)
{
//Allows the variable to be used through out the app
Session["user"] = username;
Session["domain"] = domain;
Session["manager"] = null;
if (true == authenticateUser(Session["domain"].ToString(), Session["user"].ToString(), password))
Response.Redirect(Response.ApplyAppPathModifier("Update.aspx"));
}
and front
<form id="form1" runat="server" style="Width:19%;" class="pure-form pure- form-stacked">
<asp:ScriptManager runat="server"></asp:ScriptManager>
<asp:Label ID="lblName" runat="server" Text="Name"></asp:Label>
<br />
<asp:TextBox ID="txtLoginID" Width="95%" Style="display:inline-block;" runat="server"></asp:TextBox>
</div>
<br/>
<asp:Label ID="lblpwd" runat="server" Text="Password"></asp:Label>
<asp:TextBox ID="txtPassword" Width="95%" TextMode="Password" runat="server"></asp:TextBox>
<asp:Label ID="lbldmn" runat="server" Text="Domain"></asp:Label>
<asp:DropDownList ID="ddlDomain" Width="95%" runat="server">
<asp:ListItem>hdnl.it</asp:ListItem>
<asp:ListItem>yodel.net</asp:ListItem>
</asp:DropDownList>
<asp:Label ID="lblError" runat="server" ForeColor="Red" ></asp:Label>
<br />
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<asp:Button ID="btnLogin" runat="server" Text="Login" Width="95%" OnClick="btnLogin_Click"
CssClass="button-success pure-button" />
</ContentTemplate>
</asp:UpdatePanel>
<asp:UpdateProgress ID="UpdateProgress1" runat="server"
AssociatedUpdatePanelID="UpdatePanel1">
<ProgressTemplate>
<div class="overlay"></div>
<div class="modal">
<h2>Please Wait.....</h2>
<img alt="Loading..." src="/Images/loading.gif" />
</div>
</ProgressTemplate>
</asp:UpdateProgress>
</form>

ItemCommand of Repeater is not fire with LinkButton

I have a Linkbutton inside a repeater and I want to delete the Item when the user clicks on the Linkbutton; in this case the LinkButton's ItemCommand event is not fired, my code is below:
<asp:Repeater ID="rptSubject" runat="server" OnItemCommand="rptSubject_OnItemCommand">
<ItemTemplate>
<tr>
<td><asp:CheckBox id="chkAll" runat="server"/></td>
<td><%#Eval("SubjectName") %></td>
<td>
<asp:ImageButton ID="imgbtnDelete" ImageUrl="~/assets/images/icons/delete.png" runat="server" CommandName="Delete" CommandArgument='<%#Eval("SubjectID") %>'/>
<asp:LinkButton ID="lnkEditCategory" runat="server" CommandName="EditCategory" CommandArgument='<%#Eval("SubjectID") %>' Text="Edit Category"></asp:LinkButton>
</td>
</tr>
</ItemTemplate>
my repeater's itemcommand event handler is:
protected void rptSubject_OnItemCommand(object source, RepeaterCommandEventArgs e)
{
if (e.CommandName.Equals("Delete"))
{
// some code
}
if (e.CommandName.Equals("EditCategory"))
{
// some code
}
}
when I click on the image button my item command event fires but when I click on the link button it doesn't.
The following code works for me:
<%# Page Language="C#" %>
<script type="text/c#" runat="server">
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
var data = new[]
{
new
{
SubjectID = "1",
SubjectName = "subject name 1"
},
new
{
SubjectID = "2",
SubjectName = "subject name 2"
},
};
rptSubject.DataSource = data;
rptSubject.DataBind();
}
}
protected void RptSubject_OnItemCommand(object source, RepeaterCommandEventArgs e)
{
if (e.CommandName.Equals("Delete"))
{
// some code
}
if (e.CommandName.Equals("EditCategory"))
{
// some code
}
}
</script>
<!DOCTYPE html>
<html>
<head>
<title></title>
</head>
<body>
<form id="Form1" runat="server">
<asp:Repeater ID="rptSubject" runat="server" OnItemCommand="RptSubject_OnItemCommand">
<ItemTemplate>
<div>
<asp:CheckBox id="chkAll" runat="server"/>
<%#Eval("SubjectName") %>
<asp:LinkButton ID="imgbtnDelete" runat="server" CommandName="Delete" CommandArgument='<%#Eval("SubjectID") %>' Text="Delete" />
<asp:LinkButton ID="lnkEditCategory" runat="server" CommandName="EditCategory" CommandArgument='<%#Eval("SubjectID") %>' Text="Edit" />
</div>
</ItemTemplate>
</asp:Repeater>
</form>
</body>
</html>
You also need to make sure you bind to the repeater explicitly
Protected Sub Page_Init(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Init
AddHandler rptPages.ItemCommand, AddressOf rptPages_ItemCommand
End Sub

Access a control inside a the LayoutTemplate of a ListView

How do I access a Control in the LayoutTemplate of a ListView control?
I need to get to litControlTitle and set its Text attribute.
<asp:ListView ID="lv" runat="server">
<LayoutTemplate>
<asp:Literal ID="litControlTitle" runat="server" />
<asp:PlaceHolder ID="itemPlaceHolder" runat="server" />
</LayoutTemplate>
<ItemTemplate>
</ItemTemplate>
</asp:ListView>
Any thoughts? Perhaps via the OnLayoutCreated event?
Try this:
((Literal)lv.FindControl("litControlTitle")).Text = "Your text";
The complete solution:
<asp:ListView ID="lv" OnLayoutCreated="OnLayoutCreated" runat="server">
<LayoutTemplate>
<asp:Literal ID="lt_Title" runat="server" />
<asp:PlaceHolder ID="itemPlaceHolder" runat="server" />
</LayoutTemplate>
<ItemTemplate>
</ItemTemplate>
</asp:ListView>
In codebehind:
protected void OnLayoutCreated(object sender, EventArgs e)
{
(lv.FindControl("lt_Title") as Literal).Text = "Your text";
}
This technique works for template layout; use the init event of the control:
<asp:ListView ID="lv" runat="server" OnDataBound="lv_DataBound">
<LayoutTemplate>
<asp:Literal ID="litControlTitle" runat="server" OnInit="litControlTitle_Init" />
<asp:PlaceHolder ID="itemPlaceHolder" runat="server" />
</LayoutTemplate>
<ItemTemplate>
</ItemTemplate>
</asp:ListView>
And capture a reference to the control for use in the code-behind (e.g) in the ListView's DataBound event:
private Literal litControlTitle;
protected void litControlTitle_Init(object sender, EventArgs e)
{
litControlTitle = (Literal) sender;
}
protected void lv_DataBound(object sender, EventArgs e)
{
litControlTitle.Text = "Title...";
}
For Nested LV Loop:
void lvSecondLevel_LayoutCreated(object sender, EventArgs e)
{
Literal litText = lvFirstLevel.FindControl("lvSecondLevel").FindControl("litText") as Literal;
litMainMenuText.Text = "This is test";
}
In case you need the VB version, here it is
Dim litControl = CType(lv.FindControl("litControlTitle"), Literal)
litControl.Text = "your text"

Categories

Resources