Repeater control checkbox event not fired - c#

Am having three check box in repeater control. I need the concept like radio button list.When i click the first row first checkbox, other two are checked property is set to false. suppose i check the second one means first and third are unchecked.
My Design code is here :
<asp:Repeater ID="repeaterItems" runat="server"
onitemdatabound="repeaterItems_ItemDataBound" >
<ItemTemplate>
<table id="mytable" cellspacing="0" width="100%" align="center">
<tr>
<td style="width: 18px;">
<asp:Label ID="id" runat="server" Text='<%#Bind("fld_id")%>'></asp:Label>
</td>
<td style="width: 301px;">
<asp:Label ID="Label1" runat="server" Text='<%#Bind("fld_Question")%>'></asp:Label>
</td>
<td style="width: 10px;">
<asp:CheckBox ID="CheckBox1" runat="server" AutoPostBack="true" OnCheckedChanged="CheckBox1_CheckedChanged" />
</td>
<td style="width: 30px;">
<asp:CheckBox ID="CheckBox2" runat="server" AutoPostBack="true" OnCheckedChanged="CheckBox2_CheckedChanged"/>
</td>
<td style="width: 33px;">
<asp:CheckBox ID="CheckBox3" runat="server" AutoPostBack="true" OnCheckedChanged="CheckBox3_CheckedChanged"/>
</td>
</tr>
</table>
</ItemTemplate>
</asp:Repeater>
code is :
protected void CheckBox1_CheckedChanged(object sender, EventArgs e)
{
CheckBox chk1 = sender as CheckBox;
RepeaterItem item = chk1.Parent as RepeaterItem;
CheckBox chk2 = item.FindControl("CheckBox2") as CheckBox;
chk2.Checked = false;
}
protected void CheckBox2_CheckedChanged(object sender, EventArgs e)
{
}
protected void CheckBox3_CheckedChanged(object sender, EventArgs e)
{
}
protected void repeaterItems_ItemCreated1(object sender, RepeaterItemEventArgs e)
{
RepeaterItem ri = (RepeaterItem)e.Item;
if (ri.ItemType == ListItemType.Item || ri.ItemType == ListItemType.AlternatingItem)
{
CheckBox chk = (CheckBox)e.Item.FindControl("CheckBox1");
chk.CheckedChanged += new EventHandler(CheckBox1_CheckedChanged);
}
}
CheckBox1_CheckedChanged event not fire. Please help me to fix this error.
I spent more time to solve this issue but i can't..

Just make sure that you are not binding the repeater on post back, and that viewstate is enabled on the repeater.
if(!Page.IsPostBack)
{
Repeater.Datasource = dataset(what ever source);
Repeater.Databind;
}
There is no reason why you should bind to the itemcreated event on the repeater, just to attach to the oncheckedchanged event, as this is pointless.

you can achieve by also JQuery
<head runat="server">
<title></title>
<script language="javascript" type="text/javascript" src="Scripts/jquery-1.8.2.min.js"></script>
<script language="javascript" type="text/javascript">
$(document).ready(function () {
$('.chkGroup').change(function () {
var parentTr = $(this).parent().parent();
var currentCheckID = $(this).find('input').attr("id");
$(parentTr).find('.chkGroup input').each(function () {
if (currentCheckID != $(this).attr("id")) {
$(this).removeAttr("checked");
}
});
});
});
</script>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:Repeater ID="repeaterItems" runat="server" onitemdatabound="repeaterItems_ItemDataBound">
<ItemTemplate>
<table id="mytable" cellspacing="0" width="100%" align="center">
<tr>
<td style="width: 18px;">
<asp:Label ID="id" runat="server" Text='<%#Bind("ID")%>'></asp:Label>
</td>
<td style="width: 301px;">
<asp:Label ID="Label1" runat="server" Text='<%#Bind("Name")%>'></asp:Label>
</td>
<td style="width: 10px;">
<asp:CheckBox ID="CheckBox4" runat="server" CssClass="chkGroup" />
</td>
<td style="width: 30px;">
<asp:CheckBox ID="CheckBox5" runat="server" CssClass="chkGroup" />
</td>
<td style="width: 33px;">
<asp:CheckBox ID="CheckBox6" runat="server" CssClass="chkGroup" />
</td>
</tr>
</table>
</ItemTemplate>
</asp:Repeater>
</div>
</form>
</body>

You can use the same event CheckBox1_CheckedChanged handler for all the three check-boxes OnCheckedChanged.
By using the sender object you could know which checkbox raised the event and then set the other two check-boxes checked property to false.

Related

asp.net c# FindControl inside Reapater inside HTML table return null

I have a repeater inside the HTML table the problem is I'm trying to get label value on item date bound event but it always returns null I tried to use the same code without the HTML table its working fine
so is there a way to get value while I'm using an HTML table
<table class="table table-responsive">
<asp:Repeater ID="DtImages" OnItemDataBound="DtImages_ItemDataBound" runat="server">
<HeaderTemplate>
<thead>
<tr>
<th>Image</th>
<th>update</th>
</tr>
</thead>
</HeaderTemplate>
<ItemTemplate>
<tbody>
<tr>
<td class="cart_product_img">
<img src='<%#"../../../Images/Shoping/"+ Eval("Image") %>' />
</td>
<td class="price">
<asp:ImageButton ID="btninImage" OnClick="PinImage_Click" CommandName="PinImage" ImageUrl="~/img/web/pinn.png" runat="server" />
</td>
<td class="qty">
<div class="qty-btn d-flex">
<div class="quantity">
<asp:ImageButton ID="UpdateImg" OnClick="UpdateImg_Click" CommandName="UpdateImage" ImageUrl="~/img/web/upload.png" runat="server" />
<asp:Label ID="lblProId" runat="server" Text='<%# Eval("ProID") %>' ></asp:Label>
</div>
</div>
</td>
</tr>
</tbody>
</ItemTemplate>
</asp:Repeater>
</table>
code behind
protected void DtImages_ItemDataBound(object sender,RepeaterItemEventArgs e)
{
Label Pinned =(Label) e.Item.FindControl("lblProId") ;// its return null
// some codes
}
When the repeater data bind triggers, headers, alternating rows, and a data row all are feed to that routine.
So, you have to do this:
protected void DtImages_ItemDataBound(object sender, RepeaterItemEventArgs e)
{
if ((e.Item.ItemType == ListItemType.Item) |
(e.Item.ItemType == ListItemType.AlternatingItem))
{
Label Pinned = (Label)e.Item.FindControl("lblProId");
}
}

hide column in an asp.net listview?

I have below list view , how can i hide column by code behind ?
<asp:ListView ID="AuditLogListView" runat="server" OnItemCreated="AuditLogListView_ItemCreated">
<LayoutTemplate>
<table class="table table-striped table-bordered small">
<tr class="table-secondary">
<th id="BlockHeader" runat="server" style="white-space: normal;">
<asp:Literal ID="BlockHeaderLiteral" runat="server" Text="<%$ Resources:AppResources, AuditInformationBlockHeader %>" />
</th>
</tr>
<asp:PlaceHolder runat="server" ID="ItemPlaceholder"></asp:PlaceHolder>
</table>
</LayoutTemplate>
<ItemTemplate>
<tr>
<td id="BlockStatus" runat="server">
<%# Eval("BlockStatus")%>
</td>
</tr>
</ItemTemplate>
After binding data with list view i tried below code behind but with this header text only hide but column still can still visible
if (groupOrBlockValue == 'W')
{
AuditLogListView.FindControl("BlockHeader").Visible = false;
AuditLogListView.FindControl("BlockHeaderLiteral").Visible = false;
//AuditLogListView.FindControl("BlockStatus").Visible = false;
}
Missing part of the list view?
With this:
<asp:ListView ID="LstMarks" runat="server" DataKeyNames="ID" >
<ItemTemplate>
<tr style="">
<td><asp:Textbox ID="Course" runat="server" Text='<%# Eval("Course") %>' /></td>
<td><asp:Textbox ID="Mark" runat="server" Text='<%# Eval("Mark") %>' Width="30px"/></td>
<td>
<asp:CheckBox ID="DoneLabs" runat="server" Checked = '<%# Eval("DoneLabs") %>' Width="30px"/>
</td>
</tr>
</ItemTemplate>
<LayoutTemplate>
<table id="itemPlaceholderContainer" runat="server" border="0" class="table">
<tr runat="server" style="">
<th runat="server" >Course</th>
<th runat="server">Mark</th>
<th id= "LabW" runat="server" >Completed Lab Work</th>
</tr>
<tr id="itemPlaceholder" runat="server">
</tr>
</table>
</LayoutTemplate>
</asp:ListView>
<br />
<br />
<asp:Button ID="cmdHide" runat="server" Text="Hide Lab check box" OnClick="cmdHide_Click" />
So note in the layout, we added a "id" = LabW - that lets you hide the header.
so, a simple button that would toggle (hide/show) the lvColum, then this works:
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
using (SqlCommand cmdSQL = new SqlCommand("SELECT * from StudentCourses",
new SqlConnection(Properties.Settings.Default.TEST4)))
{
cmdSQL.Connection.Open();
LstMarks.DataSource = cmdSQL.ExecuteReader();
LstMarks.DataBind();
}
}
}
protected void cmdHide_Click(object sender, EventArgs e)
{
Control ctrHeader = LstMarks.FindControl("LabW");
ctrHeader.Visible = !ctrHeader.Visible;
foreach (ListViewItem lvRow in LstMarks.Items)
{
CheckBox ckBox = (CheckBox)lvRow.FindControl("DoneLabs");
ckBox.Visible = !ckBox.Visible;
}
}
So, we get this:
And clicking on the button, we get this:
And both the values changed - they persist - even when you click again (to toggle and show the hidden columns).
Edit: =====================================================
So, say this markup:
<asp:ListView ID="AuditLogListView" runat="server"
OnItemCreated="AuditLogListView_ItemCreated">
<LayoutTemplate>
<table class="table table-striped table-bordered small">
<tr class="table-secondary">
<th id="BlockHeader" runat="server" style="white-space: normal;">
<asp:Literal ID="BlockHeaderLiteral" runat="server" Text="Hotel Name" />
</th>
</tr>
<asp:PlaceHolder runat="server" ID="ItemPlaceholder"></asp:PlaceHolder>
</table>
</LayoutTemplate>
<ItemTemplate>
<tr>
<td id="BlockStatus" runat="server">
<%# Eval("BlockStatus")%>
</td>
</tr>
</ItemTemplate>
</asp:ListView>
<asp:Button ID="Button1" runat="server" Text="Button" OnClick="Button1_Click" />
And code behind button to hide is this:
protected void Button1_Click(object sender, EventArgs e)
{
Control ctrHeader = AuditLogListView.FindControl("BlockHeaderLiteral");
ctrHeader.Visible = !ctrHeader.Visible;
foreach (ListViewItem lvRow in AuditLogListView.Items)
{
Control BlockStat = (Control)lvRow.FindControl("BlockStatus");
BlockStat.Visible = !BlockStat.Visible;
}
}
At which event have you written this code?
Required this code in the OnDataBound event. And in your code this event missing.
<asp:ListView ID="AuditLogListView" runat="server" OnItemCreated="AuditLogListView_ItemCreated" OnDataBound="AuditLogListView_DataBound">
<asp:Literal ID="BlockHeaderLiteral" runat="server" Text="<%$ Resources:AppResources, AuditInformationBlockHeader %>" /><asp:PlaceHolder runat="server" ID="ItemPlaceholder"></asp:PlaceHolder>
C# Code:
protected void AuditLogListView_DataBound(object sender, EventArgs e)
{AuditLogListView.FindControl("BlockHeaderLiteral").Visible = false;}

ListView string from aspx to codebehind

Hello I have following aspx code and when the button inside ItemTemplate is cliked i need to pass the Item.BookID into code behind and I am unsure how to do it as there can be multiple items in the view. Thank you help would be much appreciated.
<asp:ListView runat="server" ID="UserDetailBooks" DefaultMode="ReadOnly" ItemType="WebApplication1.Models.Borrowed" SelectMethod="GetBorrow" DeleteMethod="ReturnBook">
<EmptyDataTemplate>
<h3>No borrowed books!</h3>
</EmptyDataTemplate>
<LayoutTemplate>
<div style="margin-left: auto; margin-right: auto; width: 50%;">
<h4>Books in possesion:</h4>
<table style="border-spacing: 2px;">
<tr id="groupPlaceholder" runat="server">
</tr>
</table>
</div>
</LayoutTemplate>
<GroupTemplate>
<tr>
<td id="itemPlaceholder" runat="server"></td>
</tr>
</GroupTemplate>
<ItemTemplate>
<td><asp:Button runat="server" Text="Return" OnClick="ReturnBook" />
<%#:Item.BookTitle %>
</td>
</ItemTemplate>
</asp:ListView>
You could pass the id in the button attributes?
<asp:Button runat="server" Text="Return" BookID="<%#:Item.BookID %>" OnClick="ReturnBook" />
<%#:Item.BookTitle %>
void ReturnBook(object sender, EventArgs e) {
Button b = sender;
string BookId = b.Attributes["BookID"];
}

DropdownList from webservice reset after postback

My list is populated from a webservice call.
If i populate the list manually line by line its ok. I can select the item and return the selectem item with no problem e.g.
List<ListItem> oList = new List<ListItem>();
oList.Add(new ListItem("User", "0"));
oList.Add(new ListItem("Manager", "1"));
cboUsers.DataSource = oList
Thats not practical as the list I want to bind to is Dynamic, e.g.
cboUsers.DataSource = MyWebService.GetUsers() // returns List<ListItem>
No matter what I do in code I cannot get the the selected item from the list and the list ALWAYS resets itself.
Both items of code are enclosed within
if (!IsPostBack)
But when the list is bound to a web service no matter what I do (ViewState, Session anything) the list is ALWAYS reset after postback and I can NEVER get the selected item correctly.
I have tried every combination of properties on pages, controls in code and in the mark up and nothing works. I have looked at loads of articles on here and other websites and none of their examples work.
Any help would be appreciated.
[EDIT]
The full code is below.
(cboAccess, manually filled work just fine as expected)
(cboDept will fill and display but after that I can get no selection from it)
You make a selection from the dropdown (cboDept) then click the Add button (cmdAdd) which adds the text selection from the list to my database using my web service. The selection is ALWAYS shown to be the first item no matter what I select.
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
AttendanceWebServices.Service1Client oServices = new AttendanceWebServices.Service1Client();
List<ListItem> oList = new List<ListItem>();
oList.Add(new ListItem("Normal User", "0"));
oList.Add(new ListItem("Manager", "10"));
cboAccess.DataTextField = "Text";
cboAccess.DataValueField = "Value";
cboAccess.DataSource = oList;
cboAccess.DataBind();
cboDept.DataSource = oServices.GetTeamGroups().ToList();
cboDept.DataValueField = "Value";
cboDept.DataTextField = "Text";
cboDept.DataBind();
}
}
protected void cmdAdd_Click(object sender, EventArgs e)
{
AttendanceWebServices.Service1Client oServices = new AttendanceWebServices.Service1Client();
string sDept = ((ListItem)cboDept.SelectedItem).Text;
oServices.AddNewUser(sDept);
}
}
[EDIT2 - HTML]
<%# Control Language="C#" AutoEventWireup="true" CodeBehind="adduser.ascx.cs" Inherits="AttendanceWeb2.adduser" %>
<style type="text/css">
.style1
{
width: 100%;
}
</style>
<p>
</p>
<asp:scriptmanager runat="server" id="scm1">
</asp:scriptmanager>
<table class="style1">
<tr>
<td>
Name</td>
<td>
<asp:TextBox ID="TextBox2" runat="server"></asp:TextBox>
</td>
</tr>
<tr>
<td>
Department</td>
<td>
<asp:updatepanel runat="server">
<ContentTemplate>
<asp:DropDownList ID="cboDept" runat="server">
</asp:DropDownList>
</ContentTemplate>
<triggers>
<asp:AsyncPostBackTrigger ControlID="cmdAdd" />
</triggers>
</asp:updatepanel>
</td>
</tr>
<tr>
<td>
Employee ID</td>
<td>
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
</td>
</tr>
<tr>
<td>
Access Level</td>
<td>
<asp:dropdownlist runat="server" id="cboAccess"></asp:dropdownlist>
</td>
</tr>
<tr>
<td>
</td>
<td>
<asp:Button ID="cmdAdd" runat="server" onclick="cmdAdd_Click" Text="Add"
Width="100px" />
<asp:Button ID="cmdDelete" runat="server" onclick="cmdDelete_Click" Text="Delete"
Width="100px" />
</td>
</tr>
<tr>
<td>
</td>
<td>
</td>
</tr>
</table>
[EDIT 3] - Simplified Version (Still does not work)
<%# Page Language="C#" AutoEventWireup="true" CodeBehind="default.aspx.cs" Inherits="AttendanceWeb2._default" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:DropDownList ID="cboDept" runat="server"></asp:DropDownList>
<asp:Button ID="cmdAdd" runat="server" Text="Add" Width="100px"
onclick="cmdAdd_Click" />
</div>
</form>
</body>
</html>
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
AttendanceWebServices.Service1Client oServices = new AttendanceWebServices.Service1Client();
cboDept.DataSource = oServices.GetTeamGroups().ToList();
cboDept.DataValueField = "Value";
cboDept.DataTextField = "Text";
cboDept.DataBind();
}
}
protected void cmdAdd_Click(object sender, EventArgs e)
{
ListItem oItem = cboDept.SelectedItem;
string sText = oItem.Text;
string sValue = oItem.Value;
}
Make sure that you have EnableViewState set to True for your cboDept control.
EDIT
Put your table inside a form. Example:
<form id="form1" runat="server">
<asp:DropDownList ID="DropDownList1" runat="server">
</asp:DropDownList>
<asp:Button type="submit" ID="Button1" runat="server" Text="Button" OnClick="Button1_Click" />
</form>

ASP.NET loses data from form after postback - repeater inside updatepanel inside repeater

I have a ASP.NET web form where I have few checkboxes etc to make SearchCriteria object. When I click submit button I ask repeater1 to shew some records according to SearchCriteria. Inside repeater1 I have user control with updatepanel and another one repeater (ChildRepeater).
My problem: when I click send on the button after postback I lose all the data from form (eg that checkboxes was checked). Page is loading default values, but in my code I load default (all checkboxes checked) only if(!IsPostBack).
Of course I have "EnableViewState=true" in .aspx, I also tried to save data from form in session, but it also does not work (default values rewrite this settings).
When I have only one repeater (repeater1) my form after postback had all the data I put on it, so I think that there is some problem in updatepanel, but I don't know where exactly.
Could you explain me why my form loses data after page reload? I can't see any mistake..
At the bottom are my files but I have n-tier architecture so... i put only necessary files from View/BLL (DAL and sql connection works fine)
Here you have a screen how it looks: screen
ShowAgreements.aspx (it contains controls and parent repeater):
<asp:ScriptManager ID="ScriptManager1" runat="server"></asp:ScriptManager>
<asp:Repeater ID="Repeater1" runat="server" OnItemDataBound="Repeater1_ItemDataBound">
<HeaderTemplate>
<table style="border: 1px solid #0000FF; width: 1250px">
<tr style="background-color: #3d6db0; color: #000000; font-weight: bold;">
<td style="width: 150px;">Numer</td>
<td style="width: 150px;">Przedmiot umowy</td>
<td style="width: 150px;">Odbiorca</td>
<td style="width: 150px;">Dostawca</td>
<td style="width: 150px;">Rodzaj umowy</td>
<td style="width: 150px;">Charakter umowy</td>
<td style="width: 150px;">Status wypożyczenia</td>
<td style="width: 150px;">Data podpisania</td>
<td style="width: 150px;">Status</td>
</tr>
</HeaderTemplate>
<itemtemplate>
<uc1:FilesRepeaterControl runat="server" id="FilesRepeaterControl" />
</itemtemplate>
<FooterTemplate>
</table>
</FooterTemplate>
</asp:Repeater>
ShowAgreements.aspx.cs:
AgreementsSearchCriteria AgreementSearchCriteriaObj = new AgreementsSearchCriteria();
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
Controller.ReadDostawcy();
Controller.ReadOdbiorcy();
Controller.ReadPracownikOdp();
}
Controller.ReadAllAgreements();
}
protected void Repeater1_ItemDataBound(object sender, RepeaterItemEventArgs e)
{
if(e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
{
Agreement umowa = e.Item.DataItem as Agreement;
BazaUmow.Controls.FilesRepeaterControl test = e.Item.FindControl("FilesRepeaterControl") as FilesRepeaterControl;
test.umowa = umowa;
}
}
protected void szukaj_Click(object sender, EventArgs e)
{
if (IsValid == true)
{
AddNaviPoint();
Controller.ReadAllAgreements();
}
}
public AgreementSearchCollection BindUmowyResults
{
set
{
Repeater1.DataSource = value;
Repeater1.DataBind();
}
}
FilesRepeaterControl.ascx
<%# Control Language="C#" AutoEventWireup="true" CodeBehind="FilesRepeaterControl.ascx.cs" Inherits="BazaUmow.Controls.FilesRepeaterControl" %>
<tr>
<td style="width: 150px">
<asp:Button ID="btnRozwin" runat="server" Text="+" OnClick="btnRozwin_Click" />
<asp:LinkButton ID="lbl_numerUmowy" runat="server" OnClick="lbl_numerUmowy_Click"></asp:LinkButton>
</td>
<td style="width: 150px">
<asp:Label ID="lbl_przedmiotUmowy" runat="server" /></td>
<td style="width: 150px">
<asp:Label ID="lbl_odbiorca" runat="server" /></td>
<td style="width: 150px">
<asp:Label ID="lbl_dostawca" runat="server" /></td>
<td style="width: 150px">
<asp:Label ID="lbl_rodzajUmowy" runat="server" /></td>
<td style="width: 150px">
<asp:Label ID="lbl_charakterUmowy" runat="server" /></td>
<td style="width: 150px">
<asp:Label ID="lbl_statusWypozyczenia" runat="server" /></td>
<td style="width: 150px">
<asp:Label ID="lbl_dataPodpisania" runat="server" /></td>
<td style="width: 150px">
<asp:Label ID="lbl_statusUmowy" runat="server" /></td>
</tr>
<tr>
<td>
<asp:UpdatePanel ID="UpdatePanelFilesInfo" runat="server">
<ContentTemplate>
<asp:Repeater ID="filesRptr" runat="server" OnItemDataBound="filesRptr_ItemDataBound">
<HeaderTemplate>
<table style=" width:170px">
<tr style="font-weight: bold;">
<td style="width:170px;">Pliki umowy</td>
</tr>
</HeaderTemplate>
<ItemTemplate>
<tr>
<td>
<asp:LinkButton ID="lblPlikUmowy" runat="server" OnCommand="lblPlikUmowy_Command"></asp:LinkButton></td>
</tr>
</ItemTemplate>
<FooterTemplate>
</table>
</FooterTemplate>
</asp:Repeater>
<asp:Repeater ID="aneksyRptr" runat="server" OnItemDataBound="aneksyRptr_ItemDataBound">
<HeaderTemplate>
<table style=" width:170px">
<tr style="font-weight: bold;">
<td style="width:170px;">Aneksy do umowy</td>
</tr>
</HeaderTemplate>
<ItemTemplate>
<tr>
<td>
<asp:LinkButton ID="lblAneksUmowy" runat="server" OnCommand="lblAneksUmowy_Command"></asp:LinkButton></td>
</tr>
</ItemTemplate>
<FooterTemplate>
</table>
</FooterTemplate>
</asp:Repeater>
</ContentTemplate>
</asp:UpdatePanel>
</td>
</tr>
FilesRepeaterControl.ascx.cs (here we add data to parent repeater and fill two child repeaters when we click button btnRozwin)
public Agreement umowa { get; set; }
protected void Page_Load(object sender, EventArgs e)
{
lbl_numerUmowy.Text = umowa.numer_umowy.ToString();
lbl_przedmiotUmowy.Text = umowa.przedmiot_umowy.ToString();
lbl_odbiorca.Text = umowa.odbiorca_tekst.ToString();
lbl_dostawca.Text = umowa.dostawca_tekst.ToString();
lbl_rodzajUmowy.Text = umowa.rodzaj_umowy_tekst.ToString();
lbl_charakterUmowy.Text = umowa.charakter_umowy_tekst.ToString();
lbl_statusWypozyczenia.Text = umowa.status_wypozyczenia_tekst.ToString();
lbl_dataPodpisania.Text = umowa.data_podpisania.ToString("yyyy-MM-dd");
lbl_statusUmowy.Text = umowa.status_umowy.ToString();
}
protected void filesRptr_ItemDataBound(object sender, RepeaterItemEventArgs e)
{
if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
{
Plik plik = e.Item.DataItem as Plik;
LinkButton lblPlikUmowy = e.Item.FindControl("lblPlikUmowy") as LinkButton;
lblPlikUmowy.Text = plik.nazwa_pliku.ToString();
lblPlikUmowy.CommandArgument = plik.guid + plik.rozszerzenie;
}
}
protected void aneksyRptr_ItemDataBound(object sender, RepeaterItemEventArgs e)
{
if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
{
Plik plik = e.Item.DataItem as Plik;
LinkButton lblAneksUmowy = e.Item.FindControl("lblAneksUmowy") as LinkButton;
lblAneksUmowy.Text = plik.nazwa_pliku.ToString();
lblAneksUmowy.CommandArgument = plik.guid + plik.rozszerzenie;
}
}
protected void btnRozwin_Click(object sender, EventArgs e)
{
if (btnRozwin.Text == "+")
{
filesRptr.Visible = true;
aneksyRptr.Visible = true;
filesRptr.DataSource = Controller.ReadFilesByAgreement(Convert.ToInt32(lbl_numerUmowy.Text), 1);
filesRptr.DataBind();
aneksyRptr.DataSource = Controller.ReadFilesByAgreement(Convert.ToInt32(lbl_numerUmowy.Text), 2);
aneksyRptr.DataBind();
btnRozwin.Text = "-";
}
else
{
filesRptr.Visible = false;
aneksyRptr.Visible = false;
btnRozwin.Text = "+";
}
}
protected void lbl_numerUmowy_Click(object sender, EventArgs e)
{
string numer_umowy = ((LinkButton)sender).Text;
Page.Response.Redirect("~/SeeAgreementData.aspx?numer=" + numer_umowy + "&email=" + Request.QueryString["email"]);
}
}
It is because when you post back your update panel it refreshes a part(which is surrounded with update panel) of the page, so all data that was on that pannel is lost you can save all data that you need in ViewState
protected void UpdatePanelClick_OnClick(object sender, EventArgs e)
{
List<int> checkedIds = new List<int>();
//working with grid saving ids on list
ViewState["saveUpdatePanelData"] = checkedIds;
}
than on pageload after postback you can get this data and initialize
protected void Page_Load(object sender, EventArgs e)
{
if (ViewState["saveUpdatePanelData"]!= null)
{
checkedIds = ViewState["saveUpdatePanelData"] as List<int>;
}
}
it is how ViewState works.

Categories