I'm developing an Asp.net web site.
I'm using Ajax:ModalPopupExtender for displaying some information.
Html
<asp:UpdatePanel ID="upnlModelPopup" runat="server" UpdateMode="Conditional">
<ContentTemplate>
Form control goes here...............
<asp:Button ID="btnShow" runat="server" CssClass="btn" Text="Adjustment" OnClick="btnShow_Click" Enabled="true" />
<cc1:ModalPopupExtender ID="mpeAdjAmt" runat="server" TargetControlID="lblHead"
PopupControlID="pnlMsg" BackgroundCssClass="displayHide"
DropShadow="true" OkControlID="lblStsFoot" OnOkScript="setFocus()" >
</cc1:ModalPopupExtender>
<asp:Panel ID="pnlMsg" runat="server" CssClass="ErrorPanel" >
<table width="100%">
<tr>
<td >
<asp:Label ID="lblHead" CssClass="lblHead" runat="server"
Text=""></asp:Label>
</td>
</tr>
<tr>
<td >
<table class="tblTableHead" >
<tr >
<td style ="width:4%;">S.No</td>
<td style ="width:21%;">Type</td>
<td style ="width:25%;">Date</td>
<td style ="width:20%;">Amount Type</td>
<td style ="width:15%;">Amount</td>
<td style ="width:15%;">Adjust Amount</td>
</tr>
</table>
<div id="divGridStatus" style="width:100%;max-height:300px;overflow-Y:auto;overflow-X:hidden;" >
<asp:GridView ID="grvStatus" runat="server" Width="100%"
AutoGenerateColumns="false" CssClass="GridViewStyle" GridLines="None" ShowHeader="false" >
<Columns>
<asp:TemplateField >
<ItemTemplate>
<asp:LinkButton ID="lnkSNo" runat="server" CssClass="lbl"
Width="100%" OnClientClick="return false;" Font-Underline="false"
ReadOnly="true" >
<%# ((GridViewRow)Container).RowIndex + 1%>
</asp:LinkButton>
</ItemTemplate>
<ItemStyle Width="4%" />
</asp:TemplateField>
<asp:TemplateField >
<ItemTemplate>
<asp:LinkButton ID="lnkwsid" runat="server" Width="100%" OnClientClick="return false;"
ReadOnly="true" Font-Underline="false"
Text='<%# Bind("wsid") %>' >
</asp:LinkButton>
</ItemTemplate>
<ItemStyle Width="21%" />
</asp:TemplateField>
<asp:TemplateField >
<ItemTemplate>
<asp:LinkButton ID="lnknm" runat="server" Width="100%" OnClientClick="return false;"
ReadOnly="true" Font-Underline="false"
Text='<%# Bind("nm") %>' >
</asp:LinkButton>
</ItemTemplate>
<ItemStyle Width="25%" />
</asp:TemplateField>
<asp:TemplateField >
<ItemTemplate>
<asp:LinkButton ID="lnkgrp1" runat="server" Width="100%" OnClientClick="return false;"
ReadOnly="true" Font-Underline="false" Text='<%# Bind("grp1") %>' >
</asp:LinkButton>
</ItemTemplate>
<ItemStyle Width="20%" />
</asp:TemplateField>
<asp:TemplateField >
<ItemTemplate>
<asp:LinkButton ID="lnkoptid" runat="Server" CssClass="lbl"
Width="100%" OnClientClick="return false;" Font-Underline="false"
ReadOnly="true" Text='<%# Bind("optid") %>' >
</asp:LinkButton>
</ItemTemplate>
<ItemStyle Width="15%" />
</asp:TemplateField>
<asp:TemplateField >
<ItemTemplate>
<asp:LinkButton ID="lnkuid" runat="server"
Width="100%" CssClass="lbl" OnClientClick="return false;" Font-Underline="false"
ReadOnly="true" Text='<%# Bind("uid") %>' >
</asp:LinkButton>
</ItemTemplate>
<ItemStyle Width="15%" />
</asp:TemplateField>
</Columns>
<FooterStyle CssClass="FooterStyle" />
<RowStyle CssClass="RowStyle" />
<EmptyDataRowStyle CssClass="EmptyRowStyle" />
<EmptyDataTemplate>
No Data Found.
</EmptyDataTemplate>
<PagerStyle CssClass="PagerStyle" />
<SelectedRowStyle CssClass="SelectedRowStyle" />
<HeaderStyle CssClass="HeaderStyle" />
<EditRowStyle CssClass="EditRowStyle" />
<AlternatingRowStyle CssClass="AltRowStyle" />
</asp:GridView>
</div>
<table class="tblTableHead" style="padding-left:1%;">
<tr>
<td>
<asp:Label ID="lblStsFoot" runat="server" Text="" ></asp:Label>
</td>
</tr>
</table>
</td>
</tr>
<tr>
<td>
<br />
<%--OnClientClick="return CheckAdjustment();"OnClientClick="ShowWait();"--%>
<asp:Button ID="btnAdjust" runat="server" Text="Done" CssClass="btn" OnClick="btnAdjust_Click"
buttonAction="submitButton" />
<asp:Button ID="btnCancel" runat="server" Text="Cancel" CssClass="btn" OnClick="btnCancel_Click"
buttonAction="submitButton" />
</td>
</tr>
</table>
<br />
</asp:Panel>
</ContentTemplate>
</asp:UpdatePanel>
C# Code
protected void btnShow_Click(object sender, EventArgs e)
{
mpeAdjAmt.Show();
upnlModelPopup.Update();
}
protected void btnAdjust_Click(object sender, EventArgs e)
{
//Code goes here...
mpeAdjAmt.Hide();
upnlModelPopup.Update();
}
protected void btnCancel_Click(object sender, EventArgs e)
{
mpeAdjAmt.Hide();
upnlModelPopup.Update();
}
I'm showing/hiding this panel from code behind.
When i click's on show button first time it works very fine it shows panel proper.
My problem is when i click's on show button second time it doesn't show panel.
If i removed update panel it works fine when we use to show and hide panel from code behind but it starts flicker of panel on page load and works fine .
Can any one tell me what is the problem and how can i solve that.
Try doing
protected void btnShow_Click(object sender, EventArgs e)
{
mpeAdjAmt.Show();
upnlModelPopup.Update();
mpeAdjAmt.BackgroundCssClass="displayHide";
//or
//pnlMsg.CssClass="ErrorPanel";
}
protected void btnAdjust_Click(object sender, EventArgs e)
{
//Code goes here...
mpeAdjAmt.Hide();
upnlModelPopup.Update();
mpeAdjAmt.BackgroundCssClass="displayHide";
//or
//pnlMsg.CssClass="ErrorPanel";
}
protected void btnCancel_Click(object sender, EventArgs e)
{
mpeAdjAmt.Hide();
upnlModelPopup.Update();
mpeAdjAmt.BackgroundCssClass="displayHide";
//or
//pnlMsg.CssClass="ErrorPanel";
}
Related
I have a grid view which has two autogenerated Edit and delete buttons in first cell itself. The code is as below
<asp:GridView ID="grdStudent" runat="server" DataKeyNames="id" AutoGenerateColumns="false"
AutoGenerateDeleteButton="true" AutoGenerateEditButton="true"
OnRowDeleting="grdStudent_RowDeleting" OnRowDataBound="grdStudent_RowDataBound" OnRowEditing="EditGrid" OnRowCancelingEdit="CancelEdit" OnRowUpdating="UpdateGrid"
ForeColor="#333333" CellPadding="4" GridLines="Both" Width="90%"
class="table table-striped table-bordered table-hover" AllowPaging="True"
EnableSortingAndPagingCallbacks="false">
<AlternatingRowStyle BackColor="White" />
<EditRowStyle BackColor="#999999" BorderStyle="Solid" HorizontalAlign="Center"
VerticalAlign="Middle" />
<FooterStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
<HeaderStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
<PagerStyle BackColor="#284775" ForeColor="White" HorizontalAlign="Center" />
<RowStyle BackColor="#F7F6F3" ForeColor="#333333" />
<SelectedRowStyle BackColor="#E2DED6" Font-Bold="True" ForeColor="#333333"
BorderStyle="Solid" HorizontalAlign="Center" VerticalAlign="Middle" />
<SortedAscendingCellStyle BackColor="#E9E7E2" />
<SortedAscendingHeaderStyle BackColor="#506C8C" />
<SortedDescendingCellStyle BackColor="#FFFDF8" />
<SortedDescendingHeaderStyle BackColor="#6F8DAE" CssClass="table table-striped table-bordered table-hover" />
<Columns>
<asp:TemplateField HeaderText="First Name">
<ItemTemplate>
<asp:Label ID="lblID" runat="server" Text='<%#Eval("id") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="First Name">
<ItemTemplate>
<asp:Label ID="lblFirstName" runat="server" Text='<%#Eval("first_name") %>'></asp:Label>
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox runat="server" ID="txtFirstName" Text='<%#Eval("first_name") %>' Width="100px"></asp:TextBox>
</EditItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Last Name">
<ItemTemplate>
<asp:Label ID="lblLastName" runat="server" Text='<%#Eval("last_name") %>'></asp:Label>
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox runat="server" ID="txtLastName" Text='<%#Eval("last_name") %>' Width="100px"></asp:TextBox>
</EditItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Contact No">
<ItemTemplate>
<asp:Label ID="lblContactNo" runat="server" Text='<%#Eval("phone_no") %>'></asp:Label>
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox runat="server" ID="txtContactNo" Text='<%#Eval("phone_no") %>' Width="100px"></asp:TextBox>
</EditItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Email">
<ItemTemplate>
<asp:Label ID="lblEmail" runat="server" Text='<%#Eval("email") %>'></asp:Label>
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox runat="server" ID="txtEmail" Text='<%#Eval("email") %>' Width="100px"></asp:TextBox>
</EditItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Address">
<ItemTemplate>
<asp:Label ID="lblAddress" runat="server" Text='<%#Eval("address") %>'></asp:Label>
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox runat="server" ID="txtAddress" Text='<%#Eval("address") %>' Width="100px"></asp:TextBox>
</EditItemTemplate>
</asp:TemplateField>
<%-- <asp:BoundField DataField="active" HeaderText="IsActive" />--%>
<asp:TemplateField HeaderText="IsActive">
<ItemTemplate>
<asp:Label ID="lblIsActive" runat="server" Text='<%#Eval("active") %>'></asp:Label>
</ItemTemplate>
<EditItemTemplate>
<select id="ddlIsActive" class="dropdown" runat="server">
<option value="1">True</option>
<option value="2">False</option>
</select>
</EditItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Username">
<ItemTemplate>
<asp:Label ID="lblUsername" runat="server" Text='<%#Eval("username") %>'></asp:Label>
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox runat="server" ID="txtUsername" Text='<%#Eval("username") %>' Width="100px"></asp:TextBox>
</EditItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Password">
<ItemTemplate>
<asp:Label ID="lblPassword" runat="server" Text='<%#Eval("password") %>'></asp:Label>
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox runat="server" ID="txtPassword" Text='<%#Eval("password") %>' Width="100px"></asp:TextBox>
</EditItemTemplate>
</asp:TemplateField>
<%--<asp:ButtonField ButtonType="Link" --%>
</Columns>
</asp:GridView>
I need to access the delete button in Row Data bound event and add a confirmation attribute to it. I tried the below code but only Edit button is accessed at server side.
protected void grdStudent_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow && e.Row.RowIndex != grdStudent.EditIndex)
{
string text = ((LinkButton)e.Row.Cells[0].Controls[0]).Text;
//text always has the value as "Edit" never "Delete"
if (text == "delete")
{
(e.Row.Cells[0].Controls[0] as LinkButton).Attributes["onclick"] = "return confirm('Do you want to edit this row?');";
//del.OnClientClick = "return confirm('Are you certain you want to delete the record?');";
}
}
// (e.Row.Cells[0].Controls[0] as LinkButton).Attributes["onclick"] = "return confirm('Do you want to edit this row?');";
// //(e.Row.Cells[0].Controls[1] as LinkButton).Attributes["onclick"] = "return confirm('Do you want to delete this row?');";
//}
//if (e.Row.RowType == DataControlRowType.DataRow && e.Row.RowIndex == grdStudent.EditIndex)
//{
// (e.Row.Cells[0].Controls[0] as LinkButton).Attributes["onclick"] = "return confirm('Do you want to edit this row?');";
//}
}
How can I access Delete button and add a confirmation message box.
You have to add the attributes as a key/value pair.
if (e.Row.RowType == DataControlRowType.DataRow)
{
LinkButton lbEdit = e.Row.Cells[0].Controls[0] as LinkButton;
lbEdit.Attributes.Add("onclick", "return confirm('Do you want to edit this row?');");
LinkButton lbDelete = e.Row.Cells[0].Controls[2] as LinkButton;
lbDelete.Attributes.Add("onclick","return confirm('Do you want to delete this row?');");
}
#VDWWD's answer should solve the original problem.
These days, I personally like to use icon/font to look more professional.
<%# Page Language="C#" AutoEventWireup="true" CodeBehind="GridViewDemo.aspx.cs" Inherits="DemoWebForm.GridViewDemo" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" />
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css" />
</head>
<body>
<form id="form1" runat="server">
<br />
<div class="container">
<asp:GridView runat="server" ID="grdStudent"
AutoGenerateColumns="False"
OnRowEditing="grdStudent_RowEditing"
OnRowDeleting="grdStudent_RowDeleting"
OnRowDataBound="grdStudent_RowDataBound"
CssClass="table">
<Columns>
<asp:TemplateField HeaderText="Edit">
<ItemTemplate>
<asp:LinkButton runat="server" ID="EditLinkButton" CommandName="Edit">
<i class="fa fa-pencil"></i>
</asp:LinkButton>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Delete">
<ItemTemplate>
<asp:LinkButton runat="server" ID="DeleteLinkButton" CommandName="Delete">
<i class="fa fa-trash-o"></i>
</asp:LinkButton>
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="Id" HeaderText="Id" />
<asp:BoundField DataField="Name" HeaderText="Name" />
</Columns>
</asp:GridView>
</div>
</form>
</body>
</html>
Code Behind
using System;
using System.Collections.Generic;
using System.Web.UI.WebControls;
namespace DemoWebForm
{
public partial class GridViewDemo : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
grdStudent.DataSource = Collection;
grdStudent.DataBind();
}
}
protected void grdStudent_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
var d = e.Row.FindControl("DeleteLinkButton") as LinkButton;
d.Attributes.Add("onclick", "return confirm('Do you want to delete this row?');");
}
}
protected void grdStudent_RowDeleting(object sender, GridViewDeleteEventArgs e){}
protected void grdStudent_RowEditing(object sender, GridViewEditEventArgs e){}
public class Item
{
public int Id { get; set; }
public string Name { get; set; }
}
public static IList<Item> Collection = new List<Item>
{
new Item {Id = 1, Name = "One"},
new Item {Id = 2, Name = "Two"},
new Item {Id = 3, Name = "Three"}
};
}
}
This will work better for confirmation message box at Client side:
if (e.Row.RowType == DataControlRowType.DataRow)
{
// reference the Delete LinkButton
LinkButton lb = (LinkButton)e.Row.Cells[0].Controls[2];
if (lb.Text == "Delete")
{
lb.OnClientClick = "return confirm('Are you sure you want to delete this row?');";
}
}
Web page is designed using .Net framework 4.5. Web pages contains 3 Grid views as follows:
Code for Gridview is as follows:
<asp:GridView ID="grdADetails" runat="server" AutoGenerateColumns="False" CssClass="tGrid" GridLines="Horizontal" ShowFooter="True" Width="100%" OnRowCancelingEdit="grdADetails_RowCancelingEdit" OnRowCommand="grdADetails_RowCommand" OnRowDataBound="grdADetails_RowDataBound" OnRowDeleting="grdADetails_RowDeleting" OnRowEditing="grdADetails_RowEditing" OnRowUpdating="grdADetails_RowUpdating">
<Columns>
<asp:TemplateField HeaderText="Mode Of Transport">
<EditItemTemplate>
<asp:DropDownList ID="DrpTMode" runat="server" CssClass="trvGridCmbBox" Width="90%">
</asp:DropDownList>
</EditItemTemplate>
<FooterTemplate>
<table border="0" cellpadding="0" cellspacing="0" style="WIDTH: 100%">
<tr>
<td class="tGridTotal" style="Height : 25px;"></td>
</tr>
<tr>
<td class="GridEditArea" style="Height : 25px;">
<asp:DropDownList ID="DrpNTMode" runat="server" CssClass="trvGridCmbBox" Font-Size="8pt" Width="98%">
</asp:DropDownList>
</td>
</tr>
</table>
</FooterTemplate>
<HeaderTemplate>
<asp:Label ID="lblTMode" runat="server" Text="<%$ Resources:EResources, lblModeOfT %>" Width="100%"></asp:Label>
</HeaderTemplate>
<ItemTemplate>
<asp:Label ID="lblESubTypeCode" runat="server" Text='<%# Bind("ESubTypeCode") %>' Visible="False"></asp:Label>
<asp:Label ID="lblTMode" runat="server" Text='<%# Bind("TMode") %>'></asp:Label>
</ItemTemplate>
<FooterStyle HorizontalAlign="Center" VerticalAlign="Middle" />
<HeaderStyle HorizontalAlign="Center" VerticalAlign="Middle" Wrap="False" />
<ItemStyle HorizontalAlign="Center" VerticalAlign="Middle" Width="12%" />
</asp:TemplateField>
//For Date part using Ajax Control
<asp:TemplateField HeaderText="Departure On">
<EditItemTemplate>
<asp:TextBox ID="txtDeptOn" runat="server" CssClass="trvGridTextBox" Text='<%# Bind("DeptOn") %>' Width="90%"></asp:TextBox>
<ajaxToolkit:CalendarExtender ID="ceDeptOn" runat="server" Format="MM/dd/yyyy" TargetControlID="txtDeptOn" Enabled="true" Animated="true" EnabledOnClient="true" EnableViewState="true" FirstDayOfWeek="Default"/>
</EditItemTemplate>
<FooterTemplate>
<table border="0" cellpadding="0" cellspacing="0" style="WIDTH: 100%">
<tr>
<td class="tGridTotal" style="Height : 25px;"></td>
</tr>
<tr>
<td class="GridEditArea" style="Height : 25px;">
<asp:TextBox ID="txtNewDeptOn" runat="server" CssClass="trvGridTextBox" Width="100%"></asp:TextBox>
<ajaxToolkit:CalendarExtender ID="ceNewDeptOn" runat="server" Enabled="true" Format="MM/dd/yyyy" TargetControlID="txtNewDeptOn" Animated="true" EnabledOnClient="true" EnableViewState="true" FirstDayOfWeek="Default"/>
</td>
</tr>
</table>
</FooterTemplate>
<HeaderTemplate>
<asp:Label ID="lblDepartureOn" runat="server" Text="<%$ Resources:EASEResources, lblDeparOn %>" Width="100%"></asp:Label>
</HeaderTemplate>
<ItemTemplate>
<asp:Label ID="lblDeptOn" runat="server" Text='<%# Bind("DeptOn") %>'></asp:Label>
</ItemTemplate>
<FooterStyle HorizontalAlign="Center" VerticalAlign="Middle" />
<HeaderStyle HorizontalAlign="Center" VerticalAlign="Middle" />
<ItemStyle HorizontalAlign="Center" VerticalAlign="Middle" Width="10%" />
</asp:TemplateField>
//Same as above for remaining columns
//For Edit button column
<asp:TemplateField HeaderText="Edit">
<EditItemTemplate>
<asp:ImageButton ID="ImgUpdate" runat="server" CommandName="Update" ImageUrl="~/PL/images/save.png" />
<asp:ImageButton ID="ImageButton4" runat="server" CommandName="Cancel" ImageUrl="~/PL/images/remove1.png" />
</EditItemTemplate>
<FooterTemplate>
<table border="0" cellpadding="0" cellspacing="0" style="WIDTH: 100%">
<tr>
<td class="tGridTotal" style="height: 25px"></td>
</tr>
<tr>
<td class="GridEditArea" aria-orientation="vertical" style="height: 25px">
<asp:ImageButton ID="ImageButton1" runat="server" CausesValidation="False" CommandName="AddNew" CssClass="trvGridTextBox" ImageUrl="~/PL/images/save.png" />
</td>
</tr>
</table>
</FooterTemplate>
<HeaderTemplate>
<asp:Label ID="lblEdit" runat="server" Text="<%$ Resources:EResources, lblEdit %>" Width="100%"></asp:Label>
</HeaderTemplate>
<ItemTemplate>
<asp:ImageButton ID="ImageButton2" runat="server" CommandName="Edit" ImageUrl="~/PL/images/edit.png" />
</ItemTemplate>
<FooterStyle HorizontalAlign="Center" VerticalAlign="Middle" />
<HeaderStyle HorizontalAlign="Center" VerticalAlign="Middle" />
<ItemStyle HorizontalAlign="Center" VerticalAlign="Middle" Width="4%" />
</asp:TemplateField>
Remaining two grid views are created in the similar format.
<asp:GridView ID="GrdTDetail" runat="server" AutoGenerateColumns="False" CssClass="travelGrid" GridLines="Horizontal" ShowFooter="True" Width="100%" OnRowCancelingEdit="GrdTDetail_RowCancelingEdit" OnRowCommand="GrdTDetail_RowCommand" OnRowDataBound="GrdTDetail_RowDataBound" OnRowDeleting="GrdTDetail_RowDeleting" OnRowEditing="GrdTDetail_RowEditing" OnRowUpdating="GrdTDetail_RowUpdating">
<Columns>
//Other Column Code
//Edit Column Code.
<asp:TemplateField HeaderText="Edit">
<EditItemTemplate>
<asp:ImageButton ID="ImageButton3" runat="server" CausesValidation="False" CommandName="Update" ImageUrl="~/PL/images/save.png" />
<asp:ImageButton ID="ImageButton4" runat="server" CausesValidation="False" CommandName="Cancel" ImageUrl="~/PL/images/remove1.png" />
</EditItemTemplate>
<FooterTemplate>
<table border="0" style="WIDTH: 100%">
<tr>
<td class="travelGridTotal" style="Height : 25px;"></td>
</tr>
<tr>
<td class="GridEditArea" style="Height : 25px;">
<asp:ImageButton ID="ImageButton1" runat="server" CausesValidation="False" CommandName="AddNewACC" CssClass="trvGridTextBox" ImageUrl="~/PL/images/save.png" />
</td>
</tr>
</table>
</FooterTemplate>
<HeaderTemplate>
<asp:Label ID="lblEdit" runat="server" Text="<%$ Resources:EResources, lblEdit %>" Width="100%"></asp:Label>
</HeaderTemplate>
<ItemTemplate>
<asp:ImageButton ID="ImageButton2" runat="server" CausesValidation="False" CommandName="Edit" ImageUrl="~/PL/images/edit.png" />
</ItemTemplate>
<FooterStyle HorizontalAlign="Center" VerticalAlign="Middle" />
<HeaderStyle HorizontalAlign="Center" VerticalAlign="Middle" />
<ItemStyle HorizontalAlign="Center" VerticalAlign="Middle" Width="4%" />
</asp:TemplateField>
</Columns>
<FooterStyle CssClass="GridFooter" />
<HeaderStyle CssClass="travelGridhead" /
</asp:GridView>
//3rd Gridview code
<asp:GridView ID="GrdOtherExp" runat="server" AutoGenerateColumns="False" CellPadding="0" CssClass="travelGrid" GridLines="Horizontal" ShowFooter="True" Width="100%" OnRowCancelingEdit="GrdOtherExp_RowCancelingEdit" OnRowCommand="GrdOtherExp_RowCommand" OnRowDataBound="GrdOtherExp_RowDataBound" OnRowDeleting="GrdOtherExp_RowDeleting" OnRowEditing="GrdOtherExp_RowEditing" OnRowUpdating="GrdOtherExp_RowUpdating">
<Columns>
//Other Column Code
//Edit Column Code
<asp:TemplateField HeaderText="Edit">
<EditItemTemplate>
<asp:ImageButton ID="ImageButton3" runat="server" CausesValidation="False" CommandName="Update" ImageUrl="~/PL/images/save.png" />
<asp:ImageButton ID="ImageButton4" runat="server" CausesValidation="False" CommandName="Cancel" ImageUrl="~/PL/images/close.png" />
</EditItemTemplate>
<FooterTemplate>
<table border="0" cellpadding="0" cellspacing="0" style="WIDTH: 100%">
<tr>
<td class="travelGridTotal"></td>
</tr>
<tr>
<td class="GridEditArea"> <asp:ImageButton ID="ImageButton1" runat="server" CausesValidation="False" CommandName="AddNewOExp" CssClass="trvGridTextBox" ImageUrl="~/PL/images/save.png" Height="16px" Width="16px" />
</td>
</tr>
</table>
</FooterTemplate>
<HeaderTemplate>
<asp:Label ID="lblEdit" runat="server" Text="<%$ Resources:EResources, lblEdit %>" Width="100%"></asp:Label>
</HeaderTemplate>
<ItemTemplate>
<asp:ImageButton ID="ImageButton2" runat="server" CausesValidation="False" CommandName="Edit" ImageUrl="~/PL/images/edit.png" />
</ItemTemplate>
<FooterStyle HorizontalAlign="Center" VerticalAlign="Middle" />
<HeaderStyle HorizontalAlign="Center" VerticalAlign="Middle" />
<ItemStyle HorizontalAlign="Center" VerticalAlign="Middle" Width="2%" />
</asp:TemplateField>
</Columns>
<FooterStyle CssClass="GridFooter" />
<HeaderStyle CssClass="travelGridhead" /
</asp:GridView>
Each grid view has its own RowEditing, RowDataBound, RowUpdating, RowCancelEditing events. Gridview functionality is as follows:
User can enter data from footer row and using Save button having
command name as 'AddNew' saves the entered data to Item template in
row format. RowCommand event code is as follows:
protected void grdADetails_RowCommand(object sender, GridViewCommandEventArgs e)
{
DataTable dtADetails = (DataTable)ViewState["dtAccDetails"];
ViewState["dtADetails"] = dtADetails;
if (e.CommandName.Equals("AddNew"))
{
//function to add data
//function to check required fields
}
}
User can edit and update the row data on RowEding event. Row edit button has command name as 'Edit'.
protected void grdADetails_RowEditing(object sender, GridViewEditEventArgs e)
{
grdADetails.EditIndex = e.NewEditIndex;
DataTable dtADetails = (DataTable)ViewState["dtADetails"];// cache data to session
//Code for editing the functionality.
}
User can save the edited row data or cancel the editing.
After publishing the pages to production server only one grid view events get fired, remaining two grid view events do not gets fired. Each editing button has command name as 'Edit' to fire edit event. Each
<asp:UpdatePanel ID="updtpnlacademic" runat="server">
<ContentTemplate>
<td>
<asp:GridView ID="gdvwAcademic1" runat="server" OnRowCommand="gdvwAcademic1_RowCommand" OnRowDeleting="gdvwAcademic1_RowDeleting" CellPadding="4" ForeColor="#333333" GridLines="None" Width="100%" AllowSorting="True" AutoGenerateColumns="False" HorizontalAlign="Center">
<Columns>
....Other column fields
<asp:TemplateField HeaderText="Delete" ItemStyle-HorizontalAlign="Center" ShowHeader="false">
<ItemTemplate>
<asp:ImageButton ID="imgbtnacademicdelete" CommandName="Delete" OnClick="imgbtnacademicdelete_Click" CommandArgument='<%# ((GridViewRow)Container).RowIndex %>' ToolTip="Delete" runat="server" ImageAlign="Top" ImageUrl="~/Images/delete.png" Width="30" Height="25"/>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
<asp:Button ID="btndummy" runat="server" Visible="false" />
<cc1:ModalPopupExtender ID="mpacademic" runat="server" TargetControlID="btndummy" PopupControlID="Panel2" CancelControlID="btnacademicClose" BackgroundCssClass="modalBackground">
</cc1:ModalPopupExtender>
<asp:Panel ID="Panel2" runat="server" CssClass="modalPopup" HorizontalAlign="Center" style = "display:none">
<span style="color:white; font-family:'Bookman Old Style'; font-weight:bold;">Really Want To Delete This Record...!</span><br /><br /><br /><br />
<asp:Button ID="btnconfirmacademicdelete" OnClick="btnconfirmacademicdelete_Click" CssClass="BStyle" Font-Bold="true" runat="server" Text="Yes" />
<asp:Button ID="btnacademicClose" Font-Bold="true" runat="server" CssClass="BStyle" Text="Cancel" />
</asp:Panel>
</td>
</ContentTemplate>
</asp:UpdatePanel>
And following code as in the code behind ....
protected void gdvwAcademic1_RowDeleting(object sender, GridViewDeleteEventArgs e)
{
mpacademic.Show();
//System.Windows.Forms.MessageBox.Show("RowDeleting clicked after this modal popup should be displayed.....!");
}
It only show messagebox on event if uncomment messagebox but not showing modal popup
<cc1:ModalPopupExtender ID="mpacademic" runat="server" TargetControlID="btndummy" PopupControlID="Panel2" CancelControlID="btnacademicClose" BackgroundCssClass="modalBackground">
</cc1:ModalPopupExtender>
The TargetControlID property is set to btndummy and
<asp:Button ID="btndummy" runat="server" Visible="false" />
btndummy is not rendering since Visible property is set to false.
Try to replace
<asp:Button ID="btndummy" runat="server" Visible="false" />
With
<asp:Button ID="btndummy" runat="server" style="display:none" />
I have a Dto for phone numbers:
namespace Dto
{
public class PhoneNumberDto
{
public Int16 PhoneTypeId { get; set; }
public string PhoneNumber { get; set; }
}
}
and a list of this Dto:
List<PhoneNumberDto> phonenum = new List<PhoneNumberDto>();
also I have a gridview:
<table style="width: 100%">
<tr>
<td style="direction: rtl;"align="center" class="auto-style8">
<asp:UpdatePanel ID="UpdatePanelSpect1" runat="server">
<ContentTemplate>
<asp:GridView ID="GridViewCertificateType" runat="server" AutoGenerateColumns="False" CellPadding="3" OnRowCommand="GridViewCertificateType_RowCommand" OnRowDataBound="GridView1_RowDataBound" ShowFooter="True" Width="100%" Font-Names="Tahoma" Font-Size="9pt" BackColor="White" BorderColor="#CCCCCC" BorderStyle="None" BorderWidth="1px">
<Columns>
<asp:TemplateField>
<HeaderTemplate>
Phone Type
</HeaderTemplate>
<ItemTemplate>
<asp:DropDownList ID="DDLSpecialty" runat="server" Height="24px" Width="500px">
</asp:DropDownList>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField>
<ItemTemplate>
<asp:Label ID="LabelC1" runat="server" Text="Label" Visible="False"></asp:Label>
<asp:TextBox ID="TextBox_Phone" runat="server"></asp:TextBox> </ItemTemplate>
</asp:TemplateField>
<asp:TemplateField>
<FooterTemplate>
<asp:ImageButton ID="ImageButtonAddSpec" runat="server" ImageUrl="~/ImageWebForm/add.png" Width="18px" OnClick="ImageButtonAddSpec_Click" />
</FooterTemplate>
<ItemTemplate>
<asp:ImageButton ID="ImageButtonDel0" runat="server" ImageUrl="~/ImageWebForm/Delete.png" Width="18px" CommandName="Del" CommandArgument="<%# Container.DataItemIndex %>" />
</ItemTemplate>
</asp:TemplateField>
</Columns>
<FooterStyle BackColor="White" ForeColor="#000066" />
<HeaderStyle BackColor="#006699" Font-Bold="True" ForeColor="White" />
<PagerStyle BackColor="White" ForeColor="#000066" HorizontalAlign="Left" />
<RowStyle ForeColor="#000066" />
<SelectedRowStyle BackColor="#669999" Font-Bold="True" ForeColor="White" />
<SortedAscendingCellStyle BackColor="#F1F1F1" />
<SortedAscendingHeaderStyle BackColor="#007DBB" />
<SortedDescendingCellStyle BackColor="#CAC9C9" />
<SortedDescendingHeaderStyle BackColor="#00547E" />
</asp:GridView>
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="GridViewCertificateType" EventName="RowCommand" />
</Triggers>
</asp:UpdatePanel>
</td>
</tr>
</table>
Now I want to set data to my dropdown list and text box in Gridview from my list of Dot "phonenum",e.g "PhoneTypeId" set to dropdownlist and phoneNumber set to text box
You can direct bind List to your GridView and then either in the OnRowDataBound event or direct in the template you can do something like this.
First in the template.
<asp:TemplateField>
<HeaderTemplate>
Phone Type
</HeaderTemplate>
<ItemTemplate>
<asp:DropDownList ID="DDLSpecialty" Selectedvalue='<%#((PhoneNumberDto)Container.DataItem).PhoneTypeId%>' runat="server" Height="24px" Width="500px">
</asp:DropDownList>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField>
<ItemTemplate>
<asp:Label ID="LabelC1" runat="server" Text="Label"
Visible="False"></asp:Label>
<asp:TextBox ID="TextBox_Phone"
Text='<%#((PhoneNumberDto)Container.DataItem).phoneNumber %>' runat="server"></asp:TextBox>
</ItemTemplate>
</asp:TemplateField>
Or in the OnRowDataBound event using FindControl() method you can assign value to your control.
protected void GridView_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
PhoneNumberDto dtoPhone = (PhoneNumberDto)e.Row.DataItem;
((TextBox)(e.Row.FindControl("txtPhoneNo"))).Text = dtoPhone.PhoneNumber;
((DropDownList)(e.Row.FindControl("DDLSpecialty"))).SelectedValue = dtoPhone.PhoneTypeId;
}
}
I hope from above 2 option you might get your solution...
I'm using a gridview to display some data. There is an image button to display a flag. Within the GridView RowDataBound Event i'm changing the visibility of that button. But the visibility didn't get changed. Here is the code:
bool status = true; // getting this via dataset
ImageButton imgTest = (ImageButton)e.Row.FindControl("ImageButton1");
imgTest.Visible = status;
But still visibility is false.
EDIT:
Here is my HTML Code;
<asp:GridView runat="server" ID="gvScheduleView" DataKeyNames="ControlID,IsPrinted, PrintDate, DueDate"
Width="100%" ShowHeader="true" ShowFooter="true" AutoGenerateColumns="false"
OnRowDataBound="gvScheduleView_rowDataBound" Height="100%" CssClass="removePaddingRight">
<Columns>
<asp:TemplateField HeaderText="Type" HeaderStyle-HorizontalAlign="center" ItemStyle-HorizontalAlign="Center">
<ItemTemplate>
<%# Eval("Type") %>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Name" HeaderStyle-HorizontalAlign="Left" ItemStyle-Width="120">
<ItemTemplate>
<%# Eval("Name") %>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText=" Actions" HeaderStyle-HorizontalAlign="Center"
ItemStyle-Width="150" ItemStyle-HorizontalAlign="Center">
<ItemTemplate>
<div style="text-align: center;">
<table style="margin-left: 28px;">
<tr style="text-align: center;">
<td style="width: 20px">
<asp:ImageButton ID="ibDelete" runat="server" ImageUrl="~/common/images/delete.gif"
OnClick="ibDelete_click" OnClientClick="return confirm('Are you sure you wish to delete this schedule?');"
CommandArgument='<%# Eval("ControlID") %>' ToolTip="Delete Schedule" />
</td>
<td style="width: 20px">
<asp:ImageButton ID="ibRollback" runat="server" ImageUrl="~/common/images/icons/arrow_undo.png"
OnClick="ibRollback_click" CommandArgument='<%# Eval("ControlID") %>' ToolTip="Rollback print generation"
OnClientClick="return confirm('Are you sure you wish to rollback this schedule?');" />
</td>
<td style="width: 20px">
<asp:ImageButton ID="ImageButton1" runat="server" ImageUrl="~/common/images/icons/email_go.png"
OnClick="ibGenerate_click" CommandArgument='<%# Eval("ControlID") %>' />
<asp:Image ImageUrl="~/common/images/icons/cancel.png" ID="imInfo" runat="server"
Visible="false" ToolTip="DUE DATE IS INVALID - Please change to a future date" />
</td>
<td style="width: 20px">
<asp:ImageButton ID="ibEditProps" runat="server" ImageUrl="~/common/images/icons/building_edit.png"
OnClick="ibEditProps_click" CommandArgument='<%# Eval("ControlID") %>' CommandName='<%# Eval("Type") %>'
ToolTip="Edit Properties" />
</td>
</tr>
</table>
</div>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
<div id="DivBtnImgCopy" runat="server" visible = "<% =ShowHideButton() %>">
<asp:ImageButton ID="ibEditProps" runat="server"ImageUrl="~/common/images/icons/building_edit.png"
OnClick="ibEditProps_click"CommandArgument='<%# Eval("ControlID") %>' CommandName='<%# Eval("Type") %>' ToolTip="Edit Properties" />
</div>
Code Behind
protected bool ShowHideButton()
{
bool bStatus = false;
try
{
if (sCondition == "false")
{
bStatus = false;
}
else if (sCondition == "true")
{
bStatus = true;
}
return bStatus;
}
catch { }
}