I have an ASP.NET page that contains a JavaScript function as follows:
function PrintGridView(Title,Address,Terms,GridViewName) {
if (document.getElementById != null) {
var html = '<html xmlns="http://www.w3.org/1999/xhtml" dir="rtl" xml:lang="en"><HTML>\n\n';
html += '<head> <title>' + Title + '</title> <link href="Styles/Print.css" rel="stylesheet" type="text/css" /> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />';
html += "";
html += '</head>';
html += '<body> <div id="page-wrap">';
html += '<textarea id="header">'+Title+'</textarea>';
html += '<div id="identity">';
html += '<textarea id="address">'+Address+'</textarea>';
html += '<div id="logo">';
html += '<div id="logohelp">';
html +='<input id="imageloc" type="text" size="50" value="" /><br />';
html +='(max width: 540px, max height: 100px)';
html +='</div>';
html += '<img id="image" src="images/smallLogo.png" alt="logo" />';
html +='</div>';
html += '</div>';
html += '<div style="clear:both"></div>';
var tablerow = GridViewName.getElementsByTagName("tr");
html += '<table align="center" id="items">';
var td = tablerow.item(0).getElementsByTagName("th");
html += '<tr>'; // Get Table Header
for (var i = 1; i < td.length ; i++) {
html +='<th width=auto>'+td.item(i).innerText+'</th>';
}
html += '</tr>';
//Get Table Rows Data
if (tablerow.length > 10)
var Rowlen = 11;
else
var Rowlen = tablerow.length -1;
for (var j = 1; j < Rowlen; j++) {
html += '<tr class="item-row">';
var tRow= tablerow.item(j).getElementsByTagName("td");
for (var i = 1; i < 3; i++) {
html += '<td >' + tRow.item(i).innerText + '</td>';
}
html += '</tr>';
}
html += '</table>';
html += '<div id="terms"> <h5>notice</h5> <textarea>'+Terms+'</textarea></div>';
html +='</div></body></html>';
}
var printWin = window.open("", "PrintGridView");
printWin.document.open();
printWin.document.write(html);
printWin.document.close();
//printWin.print();
}
The ASP.NET page is as follows:
<%# Page Title="Damascus University-Institutes Management System" Language="C#" MasterPageFile="~/University.master" AutoEventWireup="true" CodeBehind="UniPunishmentRewardInfo.aspx.cs" Inherits="InstitutesManagementSystem.RewardPunishmentInfo" %>
<%# Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="asp" %>
<asp:Content ID="Content1" ContentPlaceHolderID="ContainerHolder" runat="server">
<script type="text/javascript">
// PrintGridView(Title,Address,Terms,GridViewName) code is here
</script>
<asp:TabContainer ID="TabContainer" runat="server" Width="700px"
ActiveTabIndex="0" OnDemand="true" AutoPostBack="false" TabStripPlacement="Top"
CssClass="fancy fancy-green" ScrollBars="None"
UseVerticalStripPlacement="false" VerticalStripWidth="120px"
onactivetabchanged="TabContainer_ActiveTabChanged" ViewStateMode="Enabled">
<asp:TabPanel ID="TabPanelSendingDownType" runat="server" HeaderText="Typs" Enabled="true" ScrollBars="Auto" OnDemandMode="Once" ViewStateMode="Enabled">
<ContentTemplate>
<asp:UpdatePanel ID="UpdatePanelSendingDownType" runat="server"
UpdateMode="Conditional">
<ContentTemplate>
<table align="center" class="tabContainerTable" >
<tr class="tabContainerTableRow">
<td align="center" >
<table align="center">
<tr>
<td>
<asp:ImageButton ID="SendingDownTypeRefreshImageButton" runat="server" ImageUrl="~/images/refresh.png" ToolTip="Refresh" onclick="SendingDownTypeRefreshImageButton_Click" />
</td>
<td>
<asp:ImageButton ID="SendingDownTypePrintImageButton" runat="server" ImageUrl="~/images/printer.png" ToolTip="Print" onclick="SendingDownTypePrintImageButton_Click" OnClientClick="PrintGridView('university',' address','Terms','"<%=SendingDownTypeGridView.ClientID>"')"/>
</td>
</tr>
</table>
</td>
</tr>
<tr class="tabContainerTableRow" >
<td align="center" class="tabContainerTableCell" ><asp:Label ID="SendingDownResultsLabel" runat="server"></asp:Label></td>
</tr>
<tr class="tabContainerTableRow">
<td align="center" class="tabContainerTableCell" >
<asp:Panel ID="PanelSendingDownType" runat="server" ScrollBars="Auto" Width="650px">
<asp:GridView ID="SendingDownTypeGridView" runat="server"
DataKeyNames="SendingDownTypeID" HeaderStyle-BackColor="#61A6F8"
ShowFooter="True" HeaderStyle-Font-Bold="true"
HeaderStyle-ForeColor="White" AutoGenerateColumns="False" HorizontalAlign="Center"
onrowcommand="SendingDownTypeGridView_RowCommand"
DataSourceID="SendingDownTypeSqlDataSource" AllowPaging="True"
AllowSorting="True">
<Columns>
<asp:TemplateField HeaderText="???????" HeaderStyle-HorizontalAlign="center">
<EditItemTemplate>
<asp:ImageButton ID="SendingDownTypeImgBtnUpdate" CommandName="Update" runat="server" ImageUrl="~/images/save.png" ToolTip="Update" Height="20px" Width="20px" />
<asp:ImageButton ID="SendingDownTypeImgBtnCancel" runat="server" CommandName="Cancel" ImageUrl="~/images/exit.png" ToolTip="Cancel" Height="20px" Width="20px" />
</EditItemTemplate>
<ItemTemplate>
<asp:ImageButton ID="SendingDownTypeImgBtnEdit" CommandName="Edit" runat="server" ImageUrl="~/images/edit.png" ToolTip="Edit" Height="20px" Width="20px" />
<asp:ImageButton ID="SendingDownTypeImgBtnDelete" CommandName="Delete" Text="Remove" runat="server" ImageUrl="~/images/-.png" ToolTip="Remove" Height="20px" Width="20px" />
</ItemTemplate>
<FooterTemplate>
<asp:ImageButton ID="SendingDownTypeImgBtnAppend" runat="server" ImageUrl="~/images/+.png" CommandName="Insert" Width="30px" Height="30px" ToolTip="Append" ValidationGroup="Tab1" />
</FooterTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="??? ??? ?????" HeaderStyle-HorizontalAlign="center">
<EditItemTemplate>
<asp:Label ID="EditSendingDownTypeIDLable" runat="server" CssClass="input" Text='<%#Eval("SendingDownTypeID") %>'/>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="ItemSendingDownTypeIDLable" runat="server" CssClass="input" Text='<%#Eval("SendingDownTypeID") %>'/>
</ItemTemplate>
<FooterTemplate>
<asp:TextBox ID="SendingDownTypeIDTextBox" runat="server" MaxLength="3" CssClass="input" />
<asp:RequiredFieldValidator ID="SendingDownTypeIDTextBoxVali" runat="server" ControlToValidate="SendingDownTypeIDTextBox" Text="*" ValidationGroup="Tab1"/>
</FooterTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="??? ?????" HeaderStyle-HorizontalAlign="center">
<EditItemTemplate>
<asp:TextBox ID="EditSendingDownTypeNameTextBox" runat="server" CssClass="input" Text='<%#Eval("SendingDownTypeName") %>'/>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="ItemSendingDownTypeNameLable" runat="server" CssClass="input" Text='<%#Eval("SendingDownTypeName") %>'/>
</ItemTemplate>
<FooterTemplate>
<asp:TextBox ID="SendingDownTypeNameTextBox" runat="server" MaxLength="50" CssClass="input"/>
<asp:RequiredFieldValidator ID="SendingDownTypeNameTextBoxVali" runat="server" ControlToValidate="SendingDownTypeNameTextBox" Text="*" ValidationGroup="Tab1"/>
</FooterTemplate>
</asp:TemplateField>
</Columns>
<HeaderStyle BackColor="#61A6F8" Font-Bold="True" ForeColor="White" />
</asp:GridView>
<asp:SqlDataSource ID="SendingDownTypeSqlDataSource" runat="server" ConflictDetection="OverwriteChanges" ConnectionString="<%$ ConnectionStrings:SqlConnectionString %>"
DeleteCommand="DELETE FROM [SendingDownType_Table] WHERE [SendingDownTypeID] =#SendingDownTypeID"
InsertCommand="IF NOT EXISTS (SELECT * FROM [SendingDownType_Table] WHERE [SendingDownTypeID] = #SendingDownTypeID ) INSERT INTO [SendingDownType_Table] ([SendingDownTypeID], [SendingDownTypeName]) VALUES (#SendingDownTypeID, #SendingDownTypeName) ELSE PRINT N'This Type ID Is Exist'"
SelectCommand="SELECT [SendingDownTypeID], [SendingDownTypeName] FROM [SendingDownType_Table] ORDER BY [SendingDownTypeID], [SendingDownTypeName]"
UpdateCommand="UPDATE [SendingDownType_Table] SET [SendingDownTypeName] = #SendingDownTypeName WHERE [SendingDownTypeID] = #SendingDownTypeID">
<DeleteParameters>
<asp:Parameter Name="SendingDownTypeID" Type="Byte" />
</DeleteParameters>
<InsertParameters>
<asp:Parameter Name="SendingDownTypeID" Type="Byte" />
<asp:Parameter Name="SendingDownTypeName" Type="String" />
</InsertParameters>
<UpdateParameters>
<asp:Parameter Name="SendingDownTypeID" Type="Byte" />
<asp:Parameter Name="SendingDownTypeName" Type="String" />
</UpdateParameters>
</asp:SqlDataSource>
</asp:Panel>
</td>
</tr>
<tr class="tabContainerTableRow">
<td><div class="clear"></div></td>
</tr>
</table>
</ContentTemplate>
</asp:UpdatePanel>
</ContentTemplate>
</asp:TabPanel>
</asp:TabContainer>
I try to pass a GridView ID to my JavaScript function that declared as follows:
'PrintGridView(Title,Address,Terms,GridViewName)'
to use it in my ASP.NET page for ImageButton on OnClientClick Event as follows:
<asp:ImageButton ID="SendingDownTypePrintImageButton" runat="server" ImageUrl="~/images/printer.png" ToolTip="Print" OnClientClick="PrintGridView('university',' address','Terms','<%=SendingDownTypeGridView.ClientID%>')"/>
but I always get an error. What should I do to solve this problem?
Change
'"<%=SendingDownTypeGridView.ClientID>"'
To
'<%=SendingDownTypeGridView.ClientID %>'
Related
I have a collapsible and expandable gridview. When i change the dropdown in my gridview the gridview collapses due to the autopostback that is caused. I need to do a autopostback since I want to populate a second dropdown based on the first dropdown. Is there a way I can expanded it after it is collapsed. I am thinking of calling the javascript but i dont now how to call it since I have little knowledge in javascript. Thank you for your help.
Here is my javascript.
function divexpandcollapse(divname) {
var div = document.getElementById(divname);
var img = document.getElementById('img' + divname);
if (div.style.display == "none") {
div.style.display = "inline";
img.src = "../images/minus.gif";
} else {
div.style.display = "none";
img.src = "../images/plus.gif";
}
}
Here is the code for my indexChanged how can I add the javascript to expand the grid.
protected void OnClosetIndexChanged(object sender, EventArgs e)
{
//Call javascript to reopen gridview
}
And here is my front end
<asp:TemplateField ItemStyle-Width="20px" >
<ItemTemplate>
<a href="JavaScript:divexpandcollapse('div<%# Eval("componente_id") %>');" >
<img id="imgdiv<%# Eval("componente_id") %>" width="9px" border="0" src="../images/plus.gif"
alt="" /></a>
<asp:ImageButton ImageUrl="~/images/select.png" runat="server" CommandName="Select" OnRowDataBound = "OnRowDataBound" Width="10px" Height="10px"/>
</ItemTemplate>
<ItemStyle Width="20px" VerticalAlign="Middle"></ItemStyle>
</asp:TemplateField>
<asp:TemplateField HeaderText="Purchase Order ID">
<ItemTemplate>
<asp:Label ID="lblPurchaseOrderID" runat="server" Text='<%#DataBinder.Eval(Container.DataItem, "componente_id") %>' ></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField>
<ItemTemplate>
<tr>
<td colspan="100%" style="background:#F5F5F5" >
<div id="div<%# Eval("componente_id") %>" style="overflow:auto; display:none; position: relative; left: 15px; overflow: auto">
<div class="header">
Cambiar la cantidad
</div>
<div class="body">
<asp:Label ID="lblType" runat="server" Text=""></asp:Label>
<br/>
<label for="validationOfTypeID">Armario:</label>
<asp:DropDownList ID="drCloset2" runat="server" Width="40%" Height="30px" AutoPostBack="True" OnSelectedIndexChanged = "OnClosetIndexChanged"></asp:DropDownList>
<br/>
<label for="validationOfTypeID">cajón:</label>
<asp:DropDownList ID = "drDrawer2" runat="server" Width="40%" Height="30px" >
</asp:DropDownList>
<br />
<asp:Label ID="lblQuantity" runat="server" Text=""></asp:Label>
<asp:DropDownList Height="30px" ID="drOperation" runat="server">
<asp:ListItem>+</asp:ListItem>
<asp:ListItem>-</asp:ListItem>
</asp:DropDownList>
<asp:TextBox width="50px" ID="txtChangeQuantity" runat="server" TextMode="Number" min="0" step="1" Value="0"></asp:TextBox>
<br/>
<asp:Button ID="btnChangeQuantity" runat="server" Text="Validar" OnClick="change_quantity_Click" />
<asp:Button ID="btnHide" runat="server" Text="Anular" AutoPostBack="True" />
</div>
<asp:DetailsView id="DetailsView1" DataKeyNames="componente_id" Runat="server" Width="300px" Font-Names="Calibri"/>
</td>
</tr>
</ItemTemplate>
</asp:TemplateField>
Here is a image of what it looks like :
<script type="text/javascript">
function AverageCalculation() {
var TtldgvRows = $("#ContentPlaceHolder1_txtGridviewRows").val();
var MonthValue1 = 0;
var MonthValue2 = 0;
var MonthValue3 = 0;
var percentageValue = 0;
for (var i = 0; i < parseInt(TtldgvRows); i++) {
MonthValue1 = $("#ContentPlaceHolder1_dgvCurrentPerformance_txtMonth1_" + i.toString()).val();
MonthValue2 = $("#ContentPlaceHolder1_dgvCurrentPerformance_txtMonth2_" + i.toString()).val();
MonthValue3 = $("#ContentPlaceHolder1_dgvCurrentPerformance_txtMonth3_" + i.toString()).val();
if (MonthValue1 == "") {
MonthValue1 = 0;
}
if (MonthValue2 == "") {
MonthValue2 = 0;
}
if (MonthValue3 == "") {
MonthValue3 = 0;
}
percentageValue = (parseFloat(MonthValue1) + parseFloat(MonthValue2) + parseFloat(MonthValue3)) / 3;
$("#ContentPlaceHolder1_dgvCurrentPerformance_lblAverage_" + i.toString()).text(percentageValue.toFixed(2));
if (percentageValue > 80) {
$("#ContentPlaceHolder1_dgvCurrentPerformance_imgBtnFileUpload_" + i.toString()).hide();
}
else {
if (parseInt(MonthValue1) != 0 && parseInt(MonthValue2) != 0 && parseInt(MonthValue3) != 0) {
$("#ContentPlaceHolder1_dgvCurrentPerformance_imgBtnFileUpload_" + i.toString()).show();
}
}
}
}
function FileuploadClick() {
var TtldgvRows1 = $("#ContentPlaceHolder1_txtGridviewRows").val();
for (var i = 0; i < parseInt(TtldgvRows1); i++) {
$("#ContentPlaceHolder1_dgvCurrentPerformance_fupCurrentPerformance_" + i.toString()).click();
return;
}
}
function getFile() {
var TtldgvRows1 = $("#ContentPlaceHolder1_txtGridviewRows").val();
var lblFileName;
for (var i = 0; i < parseInt(TtldgvRows1); i++) {
lblFileName = $("#ContentPlaceHolder1_dgvCurrentPerformance_fupCurrentPerformance_" + i.toString()).val();
$("#ContentPlaceHolder1_dgvCurrentPerformance_lblFileUpload_" + i.toString()).text(lblFileName);
}
}
</script>
Gridview Control
<asp:GridView ID="GridView3" runat="server" Width="100%" align="center" HeaderStyle-ForeColor="#4B3333"
HeaderStyle-BackColor="#C4EAC5" PageSize="10" AllowPaging="false" CssClass="table table-bordered table-hover dataTable no-footer Content"
AutoGenerateColumns="false" EmptyDataText="No Record(s) found" DataKeyNames="ID"
OnRowDataBound="dgvCurrentPerformance_RowDataBound">
<Columns>
<asp:TemplateField HeaderText="Objective Name" ItemStyle-Width="15%">
<ItemTemplate>
<asp:Label ID="lblObjectiveName" runat="server" Style="text-align: center" Text='<%# Eval("ObjectiveName") %>'></asp:Label>
<asp:HiddenField ID="hdnID" runat="server" Value='<%# Eval("ID") %>' />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Measurement Name" ItemStyle-Width="15%">
<ItemTemplate>
<asp:Label ID="lblMeasurementName" runat="server" Style="text-align: center" Text='<%# Eval("MeasurementName") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Target" ItemStyle-Width="15%">
<ItemTemplate>
<asp:Label ID="lblTarget" runat="server" Style="text-align: center" Text='<%# Eval("Target") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="CA Plan" ItemStyle-Width="15%">
<ItemTemplate>
<asp:Label ID="lblCAPlan" Style="text-align: center" runat="server" Text='<%# Eval("CAPlan") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="M1" ItemStyle-Width="15%">
<ItemTemplate>
<asp:TextBox ID="txtMonth1" runat="server" Width="80" CssClass="form-control" Text='<%# Eval("Month1") %>'
onkeypress="return ValidateKeyText(event)" Style="text-align: right;"></asp:TextBox>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="M2" ItemStyle-Width="10%">
<ItemTemplate>
<asp:TextBox ID="txtMonth2" runat="server" Width="80" CssClass="form-control" Text='<%# Eval("Month2") %>'
onkeypress="return ValidateKeyText(event)" Style="text-align: right;"></asp:TextBox>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="M3" ItemStyle-Width="10%">
<ItemTemplate>
<asp:TextBox ID="txtMonth3" runat="server" Width="80" CssClass="form-control" Text='<%# Eval("Month3") %>'
onkeypress="return ValidateKeyText(event)" Style="text-align: right;" onkeyup="AverageCalculation();"></asp:TextBox>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Average" ItemStyle-Width="10%">
<ItemTemplate>
<asp:Label ID="lblAverage" runat="server" Enabled="false" Text="" Style="text-align: center"></asp:Label>
<asp:Image ID="imgBtnFileUpload" runat="server" ImageUrl="Images/upload-button-icon-64365.png"
Width="30px" Height="30px" onclick="FileuploadClick();" ToolTip="Click here to upload"
Style="text-align: right" />
<asp:FileUpload ID="fupCurrentPerformance" runat="server" onchange="getFile();" Style="text-align: center; display: none;" />
<asp:Label ID="lblFileUpload" runat="server" Text=""></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="<center>Action</center>" Visible="false">
<ItemTemplate>
<center>
<asp:LinkButton ID="hylEdit" runat="server" CssClass="fa fa-pencil fa-fw" CausesValidation="false"
ToolTip="Edit" OnClientClick="return Edit();" data-toggle="tooltip" data-placement="top"
title="Edit" OnClick="hylEdit_Click"></asp:LinkButton>
<asp:LinkButton ID="hylDelete" runat="server" CssClass="fa fa-trash-o fa-fw" CausesValidation="false"
ToolTip="Delete" OnClientClick="return Delete();" data-toggle="tooltip" data-placement="top"
title="Delete"></asp:LinkButton>
</center>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="<input id='chkAll' onclick='checkAll();' type='checkbox'>All"
ControlStyle-Width="10%" HeaderStyle-Width="10%">
<ItemTemplate>
<center>
<asp:Label ID="dgvlblIsCurrentPerformance" runat="server" Style="text-align: center;
display: none;" Text='<%# Eval("IsCurrentPerformance")%>'></asp:Label>
<asp:CheckBox ID="chkUserID" runat="server" CssClass="checkbox" onchange="CheckOther();" />
</center>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Measurement ID" ItemStyle-Width="15%" Visible="false">
<ItemTemplate>
<asp:Label ID="lblMeasurementID" runat="server" Text='<%# Eval("MeasurementID") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Client ID" ItemStyle-Width="15%" Visible="false">
<ItemTemplate>
<asp:Label ID="lblClientID" runat="server" Text='<%# Eval("ClientID") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Objective ID" ItemStyle-Width="15%" Visible="false">
<ItemTemplate>
<asp:Label ID="lblObjectiveID" runat="server" Text='<%# Eval("ObjectiveID") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
In my application I first need to have a button on clicking the button user should see a pop up with labels and text boxes and on clicking the add button which is in modal pop up the data should be added to grid view every thing is done, but if for the first time i enter the details of a person and i click on add button then they are added to gridview, again if i enter details of another person then the details that are in gridview for first person are disappered and in gridview the second person details are displayed.But it should display both the records.Also if i again run the application after some time then the added records are not displayed in gridview that means when i run the application after some time if i have added the records previously thay should be displayed in gridview along with button but only the button is displayed but not gridview how can i display the added records even i run the application any no of times.
<%# Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="cc1" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<style type="text/css">
.Background
{
background-color: Black;
filter: alpha(opacity=90);
opacity: 0.8;
}
.Popup
{
background-color: #FFFFFF;
border-width: 3px;
border-style: solid;
border-color: black;
padding-top: 10px;
padding-left: 10px;
width: 400px;
height: 350px;
}
.lbl
{
font-size:16px;
font-style:italic;
font-weight:bold;
}
</style>
</head>
<body>
<form id="form1" runat="server">
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<asp:Button ID="Button1" runat="server" Text="Fill Form in Popup" />
<div style="margin-left:10px;margin-top:10px">
<asp:GridView ID="GridView1" AutoGenerateColumns="false" runat="server" CellPadding="2"
ForeColor="#333333" GridLines="None">
<AlternatingRowStyle BackColor="White" />
<Columns>
<asp:BoundField HeaderStyle-Width="120px" HeaderText="FirstName" DataField="FirstName" />
<asp:BoundField HeaderStyle-Width="120px" HeaderText=" MiddleName" DataField="MiddleName" />
<asp:BoundField HeaderStyle-Width="120px" HeaderText=" LastName" DataField="LastName" />
<asp:BoundField HeaderStyle-Width="120px" HeaderText="Gender" DataField="Gender" />
</Columns>
<EditRowStyle BackColor="#2461BF" />
<FooterStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
<HeaderStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
<PagerStyle BackColor="#2461BF" ForeColor="White" HorizontalAlign="Center" />
<RowStyle BackColor="#EFF3FB" />
<SelectedRowStyle BackColor="#D1DDF1" Font-Bold="True" ForeColor="#333333" />
<SortedAscendingCellStyle BackColor="#F5F7FB" />
<SortedAscendingHeaderStyle BackColor="#6D95E1" />
<SortedDescendingCellStyle BackColor="#E9EBEF" />
<SortedDescendingHeaderStyle BackColor="#4870BE" />
</asp:GridView>
</div>
<!-- ModalPopupExtender -->
<cc1:ModalPopupExtender ID="mp1" runat="server" PopupControlID="Panl1" TargetControlID="Button1"
CancelControlID="Button2" BackgroundCssClass="Background">
</cc1:ModalPopupExtender>
<asp:Panel ID="Panl1" runat="server" CssClass="Popup" align="center" style = "display:none">
<div id="irm1" style=" width: 300px; height: 250px;" runat="server" >
<table>
<tr>
<td>
<asp:Label ID="Label1" runat="server" CssClass="lbl" Text="First Name"></asp:Label>
</td>
<td>
<asp:TextBox ID="TextBox1" runat="server" Font-Size="14px" ></asp:TextBox>
</td>
</tr>
<tr>
<td>
<asp:Label ID="Label2" runat="server" CssClass="lbl" Text="Middle Name"></asp:Label>
</td>
<td>
<asp:TextBox ID="TextBox2" runat="server" Font-Size="14px" ></asp:TextBox>
</td>
</tr>
<tr>
<td>
<asp:Label ID="Label3" runat="server" CssClass="lbl" Text="Last Name"></asp:Label>
</td>
<td>
<asp:TextBox ID="TextBox3" runat="server" Font-Size="14px" ></asp:TextBox>
</td>
</tr>
<tr>
<td>
<asp:Label ID="Label4" runat="server" CssClass="lbl" Text="Gender"></asp:Label>
</td>
<td>
<asp:TextBox ID="TextBox4" runat="server" Font-Size="14px" ></asp:TextBox>
</td>
<td>
<asp:Button ID="Button3" runat="server" Text="Add" OnClick="Button3_Click" />
</td>
</tr>
</table>
</div>
<br />
<asp:Button ID="Button2" runat="server" Text="Close" />
</asp:Panel>
<!-- ModalPopupExtender -->
</form>
</body>
In my code behind-
protected void Page_Load(object sender, EventArgs e)
{
dt = new DataTable();
DataColumn dc1 = new DataColumn("FirstName");
DataColumn dc2 = new DataColumn("MiddleName");
DataColumn dc3 = new DataColumn("LastName");
DataColumn dc4 = new DataColumn("Gender");
dt.Columns.Add(dc1);
dt.Columns.Add(dc2);
dt.Columns.Add(dc3);
dt.Columns.Add(dc4);
DataRow dr1 = dt.NewRow();
GridView1.DataSource = dt;
GridView1.DataBind();
}
DataTable dt;
protected void Button3_Click(object sender, EventArgs e)
{
DataRow dr1 = dt.NewRow();
dr1[0] = TextBox1.Text;
dr1[1] = TextBox2.Text;
dr1[2] = TextBox3.Text;
dr1[3] = TextBox4.Text;
dt.Rows.Add(dr1);
GridView1.DataSource = dt;
GridView1.DataBind();
ClearFields();
}
protected void ClearFields()
{
TextBox1.Text = "";
TextBox2.Text = "";
TextBox3.Text = "";
TextBox4.Text = "";
}
carry your gridview inside Panl1 and all your code behind to webform1.cs, delete webform2, you dont need it.
I am trying to find a way to add an item to a dropdownlist using codebehind or javascript.
the dropdownlist is located within a gridview in the edit item section
<asp:GridView ID="GridView1" runat="server" CellPadding="4" ForeColor="#333333" GridLines="None" AutoGenerateColumns="False" DataKeyNames="pallet" DataSourceID="RFS_TW" AllowPaging="True" Width="100%">
<AlternatingRowStyle BackColor="White"></AlternatingRowStyle>
<Columns>
<asp:CommandField ShowEditButton="True" />
<asp:BoundField DataField="pallet" HeaderText="Pallet" ReadOnly="True" SortExpression="pallet" ItemStyle-Width="10%" >
<ItemStyle Width="10%" />
</asp:BoundField>
<asp:BoundField DataField="date_added" HeaderText="Date" SortExpression="date_added" ReadOnly="True" ItemStyle-Width="10%">
<ItemStyle Width="10%" />
</asp:BoundField>
<asp:BoundField DataField="department" HeaderText="Department" SortExpression="department" ReadOnly="True" ItemStyle-Width="10%">
<ItemStyle Width="10%" />
</asp:BoundField>
<asp:TemplateField HeaderText="sold_by" SortExpression="sold_by">
<EditItemTemplate>
<asp:DropDownList ID="soldby_ddl" runat="server" >
<asp:ListItem>Please Select</asp:ListItem>
</asp:DropDownList>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="Label2" runat="server" Text='<%# Bind("sold_by") %>'></asp:Label>
</ItemTemplate>
<ItemStyle Width="10%" />
</asp:TemplateField>
</Columns>
</asp:GridView>
Try to use
function addValues() {
var listBox = document.getElementById("soldby_ddl");
var option = new Option("value", "value");
listBox.appendChild(option);
}
or
function addValues() {
var listBox = document.getElementById("soldby_ddl");
var option = new Option("value", "value");
listBox.options[i++] = option;
}
i have content page in which i am selecting value from drop down on which gridview populate i am here showing my aspx page,
<div>
<table>
<tr>
<td>
<asp:DropDownList ID="ddlConsultant" runat="server"
AutoPostBack="True"
onselectedindexchanged="ddlConsultant_SelectedIndexChanged">
</asp:DropDownList>
</td>
<td>
</td>
<td>
<asp:TextBox ID="txtActivatedOn" runat="server">
</asp:TextBox>
<a href="javascript:show_calendar('<%=txtActivatedOn.ClientID%>','<%=txtActivatedOn.Text%>');">
<img border="0" src="./Images/calendar.gif" alt="calendar" /></a>
</td>
<td>
</td>
<td>
<asp:Button ID="btnUpdateActivated" runat="server" Text="Update Date"
class="button" />
</td>
</tr>
</table>
<div id="grdWithScroll" style="OVERFLOW: auto" onscroll="SetDivPosition()">
<asp:GridView ID="gvProjects" runat="server" AutoGenerateColumns="False" Height="150px"
Width="225px" CellPadding="4" ForeColor="#333333" GridLines="None" OnRowDeleting="gvProjects_RowDeleting"
DataKeyNames="ID" ViewStateMode="Inherit">
<AlternatingRowStyle BackColor="White" ForeColor="#284775" />
<Columns>
<asp:TemplateField>
<HeaderTemplate>
<asp:CheckBox ID="chk_All" runat="server" AutoPostBack="true" OnCheckedChanged="chk_All_CheckedChanged"/>
</HeaderTemplate>
<ItemTemplate>
<asp:CheckBox ID="chk_selector" runat="server" AutoPostBack="true" OnCheckedChanged="chk_selector_CheckedChanged" Checked='<%#bool.Parse(Eval("Proj_Flag").ToString() == "True" ? "True": "False") %>'/>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField Visible="false">
<ItemTemplate>
<asp:Label ID="lbl_ID" runat="server" Text='<%# Bind("ID") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="ProjectID" Visible="true">
<ItemTemplate>
<asp:Label ID="lblProjectID" runat="server" Text='<%# Bind("ProjectID") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<%--<asp:TemplateField HeaderText="Order #">
<ItemTemplate>
<!-- <asp:Label ID="lblOrderNumber" runat="server" Text=''></asp:Label>-->
</ItemTemplate>
</asp:TemplateField>--%>
<asp:TemplateField HeaderText="Title">
<ItemTemplate>
<a href="javascript:openPopup('DsProjectDetail.aspx?mode=1&cid=<%# Eval("ID") %>&prj=<%#Eval("Title")%>' )">
<%--<%#Eval("Title")%>--%>
<asp:Label ID="lblTitle" runat="server" Text='<%# Bind("Title") %>'></asp:Label></a>
</ItemTemplate>
<ControlStyle Width="400px" />
</asp:TemplateField>
<%-- <asp:TemplateField HeaderText="CompletionDate">
<ItemTemplate>
<asp:Label ID="lblCompletionDate" runat="server" Text='<%# Bind("CompletionDate") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>--%>
<asp:TemplateField HeaderText="ConsultantID" Visible="false">
<ItemTemplate>
<asp:Label ID="lblConsultantID" runat="server" Text='<%# Bind("CompanyID") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:CommandField DeleteImageUrl="~/Images/Delete.gif" ButtonType="Image" ShowDeleteButton="True" />
</Columns>
</asp:GridView>
</div>
<input type="hidden" id="XPos" runat="server" />
<input type="hidden" id="YPos" runat="server" />
<table>
<tr>
<td>
<asp:Button ID="btnAddProject" runat="server" CssClass="button" Text="New Project"
onclick="btnAddProject_Click" />
</td>
</tr>
</table>
</div>
Javascript i am using are,
<script type="text/javascript">
window.onload = function(){
var strCook = document.cookie;
if(strCook.indexOf("!~")!=0){
var intS = strCook.indexOf("!~");
var intE = strCook.indexOf("~!");
var strPos = strCook.substring(intS+2,intE);
document.getElementById("grdWithScroll").scrollTop = strPos;
}
}
function SetDivPosition(){
var intY = document.getElementById("grdWithScroll").scrollTop;
document.title = intY;
document.cookie = "yPos=!~" + intY + "~!";
}
</script>
<script type="text/javascript">
window.scrollBy(100, 100);
function foo() {
alert("ddd");
if (grdWithScroll != null) alert(grdWithScroll.scrollTop);
}
</script>
and at the end of the page load event i am using,
Page.ClientScript.RegisterStartupScript(GetType(), "MyKey", "SetDivPosition();", true);
i have added this line in
<%# Page Language="C#" MaintainScrollPositionOnPostback="true" ...
and also added in webconfig,
<system.web>
<pages maintainScrollPositionOnPostBack="true" >
</pages>
</system.web>
getting help from this link,
http://stackoverflow.com/questions/12092150/maintain-scroll-bar-position-of-a-div-within-a-gridview-after-a-postback
One think i wanna mention that "onscroll="SetDivPosition()" in div tag showing me warning that on scroll is not valid attribute for div tag
But after doing all this its not working for me firstly i populate gridview with dropdown when grid populate it shows check box column too in all rows that on checked save check box value in database and post back occurs if i am at bottom of grid it scroll to the top after post back
Hopes for your suggestion
Thanks