Switch case does not trigger c# asp net - c#

I made this popup that does not trigger the button I want it to. The user selects a contact, the contact is displayed with a delete button, when clicked, the confirmation popup appears with two more buttons, "Yes" and "No", they do not trigger for some reason.
ASPX:
<asp:Repeater runat="server" OnItemCommand="rptList_OnItemCommand" ID="rptList">
<HeaderTemplate>
<table id="tblListContact">
<tr id="tblRowContact">
<th>
<asp:Label runat="server" Text="TRNSLTName" />
</th>
</tr>
</HeaderTemplate>
<ItemTemplate>
<td>
<asp:LinkButton runat="server" CommandName="selectContact" CommandArgument='<%# Eval("ID") %>'><%# Eval("Name") %></asp:LinkButton>
</td>
<asp:LinkButton CssClass="deleteContact" ID="btnDelete" CommandName="deleteContact" CommandArgument='<%# Eval("ID") %>' runat="server" OnClientClick="return OpenPopup(this)">
<asp:Image ImageUrl="Images/Icons/Deleted-16x16.png" ID="DeleteContact" runat="server" />
</asp:LinkButton>
<div id="myModal" class="modal">
<div class="modal-content">
<h3 class="modalHdr">
<asp:Label runat="server" Text="TRNSLTRemove users" /></h3>
<p>
<asp:Label runat="server" Text="TRNSLTDelete Contact"></asp:Label>
</p>
<asp:Button CommandName="noBtn" CommandArgument='<%# Eval("ID") %>' ID="ButtonNo" runat="server" Text="TRNSLTNo" CssClass="popupConfirm" />
<asp:Button CommandName="yesBtn" CommandArgument='<%# Eval("ID") %>' ID="ButtonYes" runat="server" Text="TRNSLTYes" CssClass="popupConfirm" />
</div>
</div>
</ItemTemplate>
C#:
/// <summary>
/// Assigning commands to repeater.
/// </summary>
protected void rptList_OnItemCommand(object source, RepeaterCommandEventArgs e)
{
var contactId = Convert.ToInt64(e.CommandArgument);
switch (e.CommandName)
{
case "selectContact":
divRead.Visible = true;
ContactId = contactId;
var getContact = _ecSystem.GetContact(contactId);
if (getContact != null)
{
lblName.Text = getContact.Name;
lblPhone.Text = getContact.PhoneNumber;
lblMobile.Text = getContact.Cellphone;
lblAdress.Text = getContact.Street;
lblNotes.Text = getContact.Notes;
lblPage.Text = getContact.Homepage;
lblEmail.Text = getContact.Email;
imgPhone.Visible = !string.IsNullOrEmpty(lblPhone.Text);
imgMobile.Visible = !string.IsNullOrEmpty(lblMobile.Text);
imgAddress.Visible = !string.IsNullOrEmpty(lblAdress.Text);
imgNotes.Visible = !string.IsNullOrEmpty(lblNotes.Text);
imgPage.Visible = !string.IsNullOrEmpty(lblPage.Text);
imgEmail.Visible = !string.IsNullOrEmpty(lblEmail.Text);
}
break;
case "deleteContact": //It never comes to these statements
ContactId = contactId;
break;
case "noBtn": //It never comes to these statements
break;
case "yesBtn": //It never comes to these statements
if (ContactId != null)
{
_ecSystem.DeleteContact(ContactId.Value);
}
ContactId = null;
Response.Redirect("Contact.aspx");
break;
case "editContact":
divAdd.Visible = true;
_editMode = true;
var contacts = _ecSystem.GetContact(contactId);
if (contacts != null)
{
ViewState["Contacts"] = contacts;
}
break;
}
}
jQuery:
function OpenPopup($this) {
if ($($this).attr("disabled") === "disabled") {
return false;
}
var module = $($this).parent().find("#myModal");
module.show();
window.onclick = function (event) {
if (event.target === module) {
module.hide();
}
};
return false;
}

You always return false from OpenPopup. Since you use.
OnClientClick="return OpenPopup(this)"
The postback will be canceled if you return false from OnClientClick. Instead you should return true if you want to perform the server-click.
function OpenPopup($this) {
if ($($this).attr("disabled") === "disabled") {
return false;
}
var module = $($this).parent().find("#myModal");
module.show();
window.onclick = function (event) {
if (event.target === module) {
module.hide();
}
};
return true;
}
Apart from that you have a typo, following should be the same CommandName:
<asp:LinkButton ID="btnDelete" CommandName="deleteContact"
Code:
case "deleteBtn"

In your page you have
CommandName="deleteContact"
and in switch
case "deleteBtn"
they not match
in your switch you must use the same CommandName
case "deleteContact"

Related

copy text from one textbox to another on checkbox event asp.net c#

I have two address fields which has 46 textboxes and each one accepts only one character.
For eg.
Address
Line1 : 1.2.3.4....46
Line2 : 1.2.3.4...46
Now on checkbox oncheckchanged event,
I want to copy each character from textbox to another respectively and if checkbox is not checked then line one should be remained as it is.
How to accomplish this?
I tried googling but didn't help much.
<asp:TextBox runat="server" ID="line1_1" MaxLength="1" ></asp:TextBox><br/>
<asp:CheckBox runat="server" ID="if_same" Text="Same" OnCheckedChanged="if_same_CheckedChanged" AutoPostBack="true" />
<asp:TextBox runat="server" ID="line2_1" MaxLength="1" ></asp:TextBox><asp:TextBox runat="server" ID="line2_46" MaxLength="1" ></asp:TextBox>
protected void if_same_CheckedChanged(object sender, EventArgs e)
{
set_per_local();
}
public void set_per_local()
{
if (if_same.Checked == true)
{
checkIfNullEmpty();
disablelocal();
string line1_address = string.Concat(line1_1.Text,line1_46.Text);
try
{
for (int i = 0; i < line1_address.Length; i++)
{
line2_1.Text = line1_address[0].ToString();
line2_46.Text = line1_address[45].ToString();
}
}
catch (Exception)
{
throw;
}
}
else
{
Enablelocal();
}
}
public void checkIfNullEmpty()
{
if (string.IsNullOrEmpty(line1_1.Text)) line1_1.Text = " ";
if (string.IsNullOrEmpty(line1_46.Text)) line1_46.Text = " ";
}
public void disablelocal()
{
local_line1_address1.Enabled = false;
local_line1_address46.Enabled = false;
}
public void enablelocal()
{
local_line1_address1.Enabled = true;
local_line1_address46.Enabled = true;
}
I think this could be a better candidate for a client-side javascript or jQuery etc. Also, if you have followed a logical pattern for naming those 46 textboxes, in your javascript you could hook into the checkbox.changed event and start a loop walking each of the source fields and replace the target field textbox with the source value. Something like
<script>
$(".checkbox").change(function() {
if(this.checked) {
alltextboxes();
}
});
function copy alltextboxes()
{
for (int i = 0; i < 46; i++)
{
document.getElementById(tgtTbox+i).value = document.getElementById(srcTbox+i).value
}
}
</script>
Disclaimer: I have not tested this code though. I just typed it into the answer. based on your requirement, this code may need small modifications. Just note that this only works if your naming convention for the textbox labels follow a pattern (like "SourceText1, SourceText2, TargetText1, TargetText2 etc.").
I found this site more helpful.
http://www.dotnetspark.com/kb/3125-how-to-copy-textbox---text-to-another-one.aspx
<asp:TextBox runat="server" ID="TextBox1" MaxLength="1" size="1"></asp:TextBox>
<asp:TextBox runat="server" ID="TextBox2" MaxLength="1" size="1"></asp:TextBox>
<asp:TextBox runat="server" ID="TextBox3" MaxLength="1" size="1"></asp:TextBox>
<asp:TextBox runat="server" ID="TextBox4" MaxLength="1" size="1"></asp:TextBox>
<asp:CheckBox runat="server" ID="CheckBox1" Text="Same as above" onclick="CopyText()" />
<asp:TextBox runat="server" ID="iBox1" MaxLength="1" size="1"></asp:TextBox>
<asp:TextBox runat="server" ID="iBox2" MaxLength="1" size="1"></asp:TextBox>
<asp:TextBox runat="server" ID="iBox3" MaxLength="1" size="1"></asp:TextBox>
<asp:TextBox runat="server" ID="iBox4" MaxLength="1" size="1"></asp:TextBox>
<script type="text/javascript">
function CopyText() {
var cb = document.getElementById('CheckBox1');
var tb1 = document.getElementById('TextBox1');
var tb2 = document.getElementById('TextBox2');
var tb3 = document.getElementById('TextBox3');
var tb4 = document.getElementById('TextBox4');
var tb11 = document.getElementById('iBox1');
var tb12 = document.getElementById('iBox2');
var tb13 = document.getElementById('iBox3');
var tb14 = document.getElementById('iBox4');
if (cb.checked) {
tb11.value = tb1.value;
tb12.value = tb2.value;
tb13.value = tb3.value;
tb14.value = tb4.value; }
else {
tb11.value = '';
tb12.value = '';
tb13.value = '';
tb14.value = ''; }
}
}
<script>

Problems with Radio button in the datalist

Guys before asking this questions I did a lot of research on this topic but I am not able to detect the problem.I have radio button in the datalist and I am trying to get the selected radio button value.But it is showing me false for all radio button on submit button.My datalist is like this:
<asp:DataList ID="dlEmails" RepeatLayout="Flow" runat="server" >
<HeaderTemplate>
<table>
<tr>
<th>Select Email Address </th>
<th>Status</th>
</tr>
</HeaderTemplate>
<ItemTemplate>
<tr>
<td>
<asp:RadioButton ID="rbtnSelect" Text='<%#Eval("Emails") %>' onclick='fnrad(this);' GroupName="a" Checked='<%#Eval("Primary") %>' runat="server" /><br />
(<asp:Label ID="lablel" runat="server" Text='<%#Eval("Verified") %>'> </asp:Label>)
</td>
<td valign="middle">
<asp:Label ID="lblID" Style="display: none;" runat="server" Text='<%#Eval("Id") %>'> </asp:Label>
<asp:Label ID="Label1" runat="server" Text='<%#Eval("Main") %>'> </asp:Label>
</td>
</tr>
</ItemTemplate>
<FooterTemplate>
</table>
</FooterTemplate>
</asp:DataList>
Javascript for allowing only single radio button selection at a time is like this:
<script>
function fnrad(rbtn) {
var radioList = document.getElementsByTagName("input");
for (var i = 0 ; i < radioList.length; i++) {
if (radioList[i].type == "radio") {
radioList[i].name = 'a';
radioList[i].checked = false;
}
}
rbtn.checked = true;
rbtn.setAttribute("Checked","checked");
}
</script>
And my code behind is like this:
public partial class Member_EmailList : System.Web.UI.Page
{
EmailsBAL _mbl = new EmailsBAL(SessionContext.SystemUser);
DataSet _ds = new DataSet();
URLMessage URLMessage = new URLMessage();
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
LoadData();
}
}
private void LoadData()
{
_mbl.LoadByUser(_ds, 1);//SessionContext.SystemUser;
dlEmails.DataSource = _ds.Tables[_mbl.SqlEntityX];
dlEmails.DataBind();
}
protected void lnkConfirm_Click(object sender, EventArgs e)
{
RadioButton rb;
Label lbl;
int id = 0;
foreach (DataListItem di in dlEmails.Items)
{
rb = (RadioButton)di.FindControl("rbtnSelect");
if (rb.Checked == true)
{
lbl = (Label)di.FindControl("lblID");
id = WebHelper.Cast(lbl.Text, 0);
}
}
//Response.Redirect("~/Member/ConfirmEmail.aspx?" + URLMessage.Encrypt("SystemUser=" + SessionContext.SystemUser + "Id=" + id.ToString()));
}}
I tried your javascript function and experienced your problem
I would like to suggest to use Jquery on your javascript function. I refactored your jav fuction to this.
function fnrad(rbtn) {
$('input').removeAttr('checked');
$(rbtn).prop('checked', true);
}
This works perfectly on my end. Please let me know if you still encountering the issue.

Getting value from textarea in ASP.NET repeater?

I have an asp.net repeater control, displaying data from a sql db.
I have delete, edit and save buttons displaying next to each record, sort of like an admin.
When edit is clicked, hidden textboxes appear in place of the literals that were displaying the data.
When save is clicked, the new values should be saved to the db (which they are), and the literals display the new value.
But the new value strings are returning as empty strings. They're not null, but the string contains no characters!
This worked fine when I had two TextBox's , however when I switched one to a HTMLTextArea , this happened!
Here is my relevant code...
if (e.CommandName == "edit")
{
((TextBox)e.Item.FindControl("Onebox")).Visible = true;
((TextBox)e.Item.FindControl("Onebox")).Text = ((Literal)e.Item.FindControl("onelit")).Text;
((HtmlTextArea)e.Item.FindControl("Threebox")).Visible = true;
((HtmlTextArea)e.Item.FindControl("Threebox")).Value = ((Literal)e.Item.FindControl("threelit")).Text;
DataTable dt = new DataTable();
DataTable dt2 = new DataTable();
((Literal)e.Item.FindControl("onelit")).Visible = false;
((Literal)e.Item.FindControl("threelit")).Visible = false;
((LinkButton)e.Item.FindControl("LinkButton2")).Visible = false;
((LinkButton)e.Item.FindControl("LinkButton3")).Visible = true;
}
if (e.CommandName == "save")
{
string newoneval = ((TextBox)e.Item.FindControl("Onebox")).Text;
string newtwoval = ((HtmlTextArea)e.Item.FindControl("Threebox")).Value;
((TextBox)e.Item.FindControl("Onebox")).Visible = false;
((Literal)e.Item.FindControl("onelit")).Text = ((TextBox)e.Item.FindControl("Onebox")).Text;
((HtmlTextArea)e.Item.FindControl("Threebox")).Visible = false;
((Literal)e.Item.FindControl("threelit")).Text = ((HtmlTextArea)e.Item.FindControl("Threebox")).Value;
((Literal)e.Item.FindControl("onelit")).Visible = true;
((Literal)e.Item.FindControl("threelit")).Visible = true;
((LinkButton)e.Item.FindControl("LinkButton2")).Visible = true;
((LinkButton)e.Item.FindControl("LinkButton3")).Visible = false;
if(newoneval != null && newtwoval != null)
{
SqlDataReader dataReader;
String editstr = "update news set title = '" + newoneval + "', short_desc ='" + newtwoval + "' where pk_ID = #pk_ID";
SqlCommand command = new SqlCommand(editstr, conn);
command.Parameters.AddWithValue("#pk_ID", e.CommandArgument);
try
{
conn.Open();
dataReader = command.ExecuteReader();
dataReader.Close();
command.Dispose();
conn.Close();
BindRepeater();
}
catch (Exception exc)
{
Response.Write(exc);
}
}
else
{
Response.Write("No value");
}
and here is the asp repeater template...
<asp:Repeater ID="list_holder" runat="server" OnItemCommand="runCommands">
<ItemTemplate>
<table>
<tr>
<!-- FIRST BOX CONTROLS ---------------->
<td class="cells">
<asp:Textbox id="Onebox"
text=''
runat="server"
enabled="true"
visible="false">
</asp:Textbox>
<asp:Literal id="onelit"
runat="server"
text='<%# DataBinder.Eval(Container.DataItem ,"title") %>'
/>
</td>
<td class="cells">
<textarea id="Threebox"
text=''
runat="server"
enabled="true"
Visible="false">
</textarea>
<asp:Literal id="threelit"
text='<%# DataBinder.Eval(Container.DataItem ,"short_desc") %>'
runat="server"
/>
</td>
<!-------------------------------------->
<!---- Link Buttons ------------------------>
<td class="cells">
<asp:LinkButton ID="LinkButton1"
runat="server"
CommandName="delete"
OnClientClick='javascript:return confirm("Are you sure you want to delete?")'
CommandArgument='<%# DataBinder.Eval(Container.DataItem, "pk_ID") %>'
CausesValidation="false">Delete</asp:LinkButton>
</td>
<td class="cells">
<asp:LinkButton ID="LinkButton2"
runat="server"
CommandName="edit"
CommandArgument='<%# DataBinder.Eval(Container.DataItem, "pk_ID") %>'
CausesValidation="false"
Visible ="true">Edit</asp:LinkButton>
<asp:LinkButton ID="LinkButton3"
runat="server"
CommandName="save"
CommandArgument='<%# DataBinder.Eval(Container.DataItem, "pk_ID") %>'
CausesValidation="false"
Visible ="false">Save</asp:LinkButton>
</td>
<!-------------------------------------------------->
</tr>
</table>
</ItemTemplate>
</asp:Repeater>
Why are both the strings returning empty, when before they were returning correctly?
In ASP.NET when you set visible to false, Control don't render on page.
For more see MSDN.

Drag-Drop item from one data group to another data group in Telerik RadListView

I am trying to use the Telerik RadListView Drag-Drop feature:
http://demos.telerik.com/aspnet-ajax/listview/examples/datagrouping/defaultcs.aspx
The code below works fine but loops through all the items to find the "e.DestinationHtmlElement" which is not efficient. I want to be able to drag an item from one data group to another data group for Telerik RadListView with a better algorithm. How can I do that?
ASPX Code:
<telerik:RadListView runat="server" ID="Lsv_Vis" AllowPaging="True" PageSize="50"
ItemPlaceholderID="Phi_Vis_I" GroupPlaceholderID="Phi_Vis_G"
DataKeyNames="url_id, lst_id, url_name, url_address"
ClientDataKeyNames="url_id, lst_id, url_name, url_address"
OnItemDrop="CsVisItemDrop" OnItemDataBound="CsVisIDB" DataSourceID="Sql_Vis">
</telerik:RadListView>
<DataGroups>
<telerik:ListViewDataGroup GroupField="lst_id" DataGroupPlaceholderID="Phi_Vis_G">
<DataGroupTemplate>
<div class="Div_Vis_Grp"><span class="Spn_Vis"><%# (Container as RadListViewDataGroupItem).AggregatesValues["lst_name"].ToString() %></span></div>
<asp:Panel ID="Pnl_Vis" runat="server" CssClass="Pnl_Vis" ToolTip='<%# (Container as RadListViewDataGroupItem).DataGroupKey %>' onmouseover='this.className += " Vis_Sel";' onmouseout='this.className = this.className.split(" Vis_Sel").join("");'>
<asp:PlaceHolder ID="Phi_Vis_I" runat="server" />
</asp:Panel>
</DataGroupTemplate>
<GroupAggregates>
<telerik:ListViewDataGroupAggregate Aggregate="Max" DataField="lst_name" />
</GroupAggregates>
</telerik:ListViewDataGroup>
</DataGroups>
<ItemTemplate>
<div class="Div_Vis_Item rlvI">
<asp:Panel ID="Pnl_Vis" runat="server" ToolTip='<%# Eval("lst_id") %>' CssClass="Div_Vis_Item" onmouseover='this.className += " Vis_Sel";' onmouseout='this.className = this.className.split(" Vis_Sel").join("");'>
<a class="Hyp_Vis" runat="server" href='<%# Eval("url_address") %>' target="_blank">
<div class="Div_Vis_Body">
<div class="Div_Vis_Con">
<asp:Panel ID="Div_Vis_Con" runat="server" class="Div_Vis_Con" ToolTip='<%# Eval("lst_id") %>' ></asp:Panel>
</div>
</div>
<div class="Div_Vis_Link">
<asp:Label ID="Lbl_VisI" runat="server" Text='<%# Eval("url_name_short") %>' ToolTip='<%# Eval("url_name") %>'/>
</div>
</a>
</asp:Panel>
</div>
</ItemTemplate>
C# Code:
protected void CsVisItemDrop (object sender, RadListViewItemDragDropEventArgs e)
{
if (e.DestinationHtmlElement.IndexOf("Div_Vis_Con") < 0)
{
return;
}
foreach (RadListViewDataItem di in Lsv_Vis.Items)
{
Panel pnl = di.FindControl("Div_Vis_Con") as Panel;
if (pnl != null && pnl.ClientID == e.DestinationHtmlElement)
{
string uid = e.DraggedItem.GetDataKeyValue("url_id").ToString();
string lid = pnl.ToolTip.ToString();
using (SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["Con_Str"].ToString()))
{
using (SqlCommand cmd = new SqlCommand("UPDATE [MyTable] SET lst_id = #lst_id WHERE url_id = #url_id", conn))
{
cmd.Parameters.Add("#lst_id", SqlDbType.VarChar).Value = lid;
cmd.Parameters.Add("#url_id", SqlDbType.VarChar).Value = uid;
try
{
conn.Open();
cmd.ExecuteNonQuery();
conn.Close();
}
catch { }
}
}
}
}
Lsv_Vis.Rebind();
}

Click page index on gridview not call to PageIndexChanging event

I have a gridview gdvNotification. When the page load first time: My gridview have paging.
My problem is:
when the page load first time: i click on the page index, but page index not changing. I debuged: when click on the page index, call to codebehide but not call to gdvNotification_PageIndexChanging event.
On browser I'm thying to use script javascript:__doPostBack('ctl00$MainContent$gdvNotification','Page$2') in console of browser, it working properly. The gdvNotification_PageIndexChanging event was called.
Here is my griview :
<asp:GridView ID="gdvNotification" runat="server" AutoGenerateColumns="False" Style="width: 100%;"
BorderWidth="0px" CellSpacing="0" CellPadding="0" GridLines="None" PageSize="1"
AllowPaging="True" ShowHeader="false" OnPageIndexChanging="gdvNotification_PageIndexChanging">
<HeaderStyle CssClass="BasicColumnTitle" />
<Columns>
<asp:TemplateField>
<ItemTemplate>
<asp:Panel ID="panel1" runat="server" Width="100%" Height="618" ScrollBars="Vertical">
<table style="width: 100%;">
<tbody>
<tr style="height: 40px">
<td class="BasicValue" style="vertical-align: bottom;padding-left:2em">
<div>
<asp:Label ID="lblhead" CssClass="bold" runat="server" Text='<% #Eval("Subject")%>' Style=" font-weight: bold"></asp:Label>
</div>
</td>
</tr>
<tr style="height: 40px">
<td class=" BasicValue" style="vertical-align: bottom ;padding-left: 2em;">
<div>
<asp:Label ID="Label2" runat="server" Style=" font-weight: bold" Text='<% #Eval("AuthorName")%>'></asp:Label><asp:Label
ID="Label3" runat="server" Style="float: right" Text='<%# string.Format("{0:yyyy/MM/dd hh:mm}",Eval("BulletinDateFrom"))%>'></asp:Label></div>
</td>
</tr>
<tr style="height: 40px">
<td class="BasicValue" style="vertical-align: bottom">
<div>
<asp:Label ID="lblSection" runat="server" Style="padding-left: 2em;" Text='<%# GetSectionName(Eval("Id").ToString())%>'></asp:Label>
</div>
</tr>
<tr style="height: 497px;">
<td class="BasicValue" style="text-align: left; vertical-align: top; padding-left:2em ">
<asp:Label ID="lblContent" runat="server"
Text='<% #Eval("Contents")%>'></asp:Label>
</td>
</tr>
</tbody>
</table>
</asp:Panel>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
Page load method:
protected void Page_Load(object sender, EventArgs e)
{
logger.Debug("Handle event page load.");
if (!IsPostBack)
{
try
{
MasterDataHelper.RefreshCacheHeadLine();
//Get time display from system parameter
logger.Debug("Get limit new data display list.");
IList<SystemParamEntity> limitNewDataDisplayList = MasterDataHelper.GetSystemParamEntityByKbn(limitDataKBN);
IList<decimal> limitNewDataDisplayList1 =
(from item in limitNewDataDisplayList where item.DelFlg == false select item.Param1).ToList();
if (!limitNewDataDisplayList1.Any())
{
string msg = string.Format(Messages.I00010, "新規表示期間");
logger.Error(msg);
}
else
{
limitNewDataDisplay = limitNewDataDisplayList1[0];
this.hdflimitNewDataDisplay.Value = limitNewDataDisplay.ToString();
}
//Get data from session and cache
GetDataFromSessionAndCache();
//TODO: check business input datetime.now
var searchresult = ProcessFuzzySearch(DateTime.Now, SessionUtil.GetFromSession<string>(SESSION_FUZZYSEARCH));
txtFuzzySearch.Text = SessionUtil.GetFromSession<string>(SESSION_FUZZYSEARCH);
lblDate.Text = string.Format("{0}年{1}月{2}日({3})", DateTime.Today.Year, DateTime.Today.Month, DateTime.Today.Day,
GetDayOfWeek((int)DateTime.Now.DayOfWeek));
pnPageIndex.Visible = false;
grvHeadline.DataSource = searchresult;
grvHeadline.DataBind();
if (searchresult.Count > 0)
{
string notificationIdSelected = searchresult[0].Id;
hdfNotificationIdSelected.Value = searchresult[0].Id;
HeadlineSelected(notificationIdSelected, 0);
grvHeadline.SelectRow(0);
}
else
{
//if: notification.count=0 => disable button edit notification
btnEditNotification.Enabled = false;
ClearDataAndDisplayForGridNotification();
}
}
catch (ApplicationException ex)
{
logger.Error(ex);
}
//Check permission for button add new head line and update notification
checkPermission();
}
}
}
Bind data for gridview grvNotification method:
private void HeadlineSelected(string notificationIdSelected, int index)
{
logger.Debug("Head line selected");
GetDataFromSessionAndCache();
IList<InformationEntity> infoNotificationList = new List<InformationEntity>();
if (string.IsNullOrEmpty(notificationIdSelected))
{
//Clear
ClearDataAndDisplayForGridNotification();
btnEditNotification.Enabled = false;
}
else
{
infoNotificationList = MasterDataHelper.GetInformationByHighOrderId(notificationIdSelected);
logger.Debug("Notification list not null");
if (infoNotificationList != null)
{
if (infoNotificationList.Count == 0)
{
pnPageIndex.Visible = false;
hdfNotificationId.Value = string.Empty;
btnEditNotification.Enabled = false;
}
else
{
if (infoNotificationList.Count == 1)
{
fakepanel.Visible = true;
}
else
{
fakepanel.Visible = false;
}
if (base.IsPermission(PERMISSION_INFORMATION_FOLLOWUP))
{
btnEditNotification.Enabled = true;
}
pnPageIndex.Visible = true;
gdvNotification.PageIndex = index;
hdfNotificationId.Value = infoNotificationList[index].Id;
gdvNotification.DataSource = infoNotificationList;
gdvNotification.DataBind();
}
logger.Debug("Set value for label total page");
lblTotalPage.Text = gdvNotification.PageCount.ToString(CultureInfo.InvariantCulture);
lbPageIndex.Text = gdvNotification.PageCount == 0
? gdvNotification.PageCount.ToString(CultureInfo.InvariantCulture)
: (gdvNotification.PageIndex + 1).ToString(CultureInfo.InvariantCulture);
lbTotal.Text = infoNotificationList.Count().ToString(CultureInfo.InvariantCulture);
}
}
}
Event pageindex changing of gridview gdvNotification:
protected void gdvNotification_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
logger.Debug("Gridview Headline page index changing .");
//gdvNotification.PageIndex = e.NewPageIndex;
HeadlineSelected(hdfNotificationIdSelected.Value, e.NewPageIndex);
//gdvNotification.DataBind();
lbPageIndex.Text = (e.NewPageIndex + 1).ToString(CultureInfo.InvariantCulture);
}
What is happening?
" call to codebehide but not call to gdvNotification_PageIndexChanging event."
If you are getting a postback but the the function isn't being called, maybe something in the Page_Load method is stopping things from happening. You aren't refilling the GridView are you? Did you forget
if (!Page.IsPostBack)

Categories