Duplicate values table gridview - c#

I'm trying to use a table in a gridview, but I have a problem.
<%# Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs" Inherits="WebApplication4.WebForm1" %>
<!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 id="Head1" runat="server">
<title></title>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
<script type="text/javascript">
$("[src*=plus]").live("click", function () {
$(this).closest("tr").after("<tr><td></td><td colspan = '999'>" + $(this).next().html() + "</td></tr>")
$(this).attr("src", "images/minus.png");
});
$("[src*=minus]").live("click", function () {
$(this).attr("src", "images/plus.png");
$(this).closest("tr").next().remove();
});
</script>
</head>
<body>
<form id="form1" runat="server">
<asp:GridView ID="gvCustomers" runat="server" AutoGenerateColumns="false" CssClass="Grid"
DataKeyNames="ABI" OnRowDataBound="OnRowDataBound" >
<Columns>
<asp:TemplateField>
<ItemTemplate>
<img alt = "" style="cursor: pointer" src="pics/plus.png" />
<asp:Panel ID="pnlOrders" runat="server" Style="display: none">
<asp:TextBox ID="gvOrders" runat="server" CssClass = "ChildGrid" Text="aa">
</asp:TextBox>
</asp:Panel>
</ItemTemplate>
</asp:TemplateField>
<asp:ButtonField ItemStyle-Width="150px" DataTextField="N017" HeaderText="Contact Name"/>
<asp:BoundField ItemStyle-Width="150px" DataField="N028" HeaderText="City" />
</Columns>
</asp:GridView>
</form>
</body>
</html>
When I expand and click on the ButtonField, page automatically will be reloaded and in the textbox I have the duplicate values.
What's wrong?

Related

the sorting of Gridview using jQuery Table Sorter of asp.net webfrom

I have two pages
1.jQueryGridviewSortWithoutMasterpage.aspx
<%--this is without master page--%>
<%# Page Language="C#" AutoEventWireup="true" CodeFile="jQueryGridviewSortWithoutMasterpage.aspx.cs" Inherits="jQueryGridviewSort" %>
<!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>
<style type="text/css">
th
{
cursor:pointer;
background-color:#dadada;
color:Black;
font-weight:bold;
text-align:left;
}
th.headerSortUp
{
background-image: url(images/asc.gif);
background-position: right center;
background-repeat:no-repeat;
}
th.headerSortDown
{
background-image: url(images/desc.gif);
background-position: right center;
background-repeat:no-repeat;
}
td
{
border-bottom: solid 1px #dadada;
}
</style>
<%--<script src="scripts/jquery-1.4.3.min.js" type="text/javascript"></script>
<script src="scripts/jquery.tablesorter.min.js" type="text/javascript"></script> --%>
<script src="Scripts/jquery-1.4.1.min.js" type="text/javascript"></script>
<script src="Scripts/jquery.tablesorter.min.js" type="text/javascript"></script>
<script type="text/javascript">
$(document).ready(function () {
$("#GridView1").tablesorter();
});
</script>
</head>
<body>
<form id="form1" runat="server">
<div>
</div>
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" GridLines="Both"
DataKeyNames="RoleID" DataSourceID="SqlDataSource1">
<Columns>
<asp:BoundField DataField="RoleID" HeaderText="RoleID" InsertVisible="False"
ReadOnly="True" SortExpression="RoleID" />
<asp:BoundField DataField="RoleName" HeaderText="RoleName"
SortExpression="RoleName" />
<asp:CheckBoxField DataField="IsActive" HeaderText="IsActive"
SortExpression="IsActive" />
<asp:BoundField DataField="AddedBy" HeaderText="AddedBy"
SortExpression="AddedBy" />
<asp:BoundField DataField="AddedDate" HeaderText="AddedDate"
SortExpression="AddedDate" />
<asp:BoundField DataField="UpdatedBy" HeaderText="UpdatedBy"
SortExpression="UpdatedBy" />
<asp:BoundField DataField="UpdatedDate" HeaderText="UpdatedDate"
SortExpression="UpdatedDate" />
</Columns>
</asp:GridView>
<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="<%$ ConnectionStrings:WSMSConnectionString %>"
SelectCommand="SELECT [RoleID], [RoleName], [IsActive], [AddedBy], [AddedDate], [UpdatedBy], [UpdatedDate] FROM [Role]">
</asp:SqlDataSource>
</form>
</body>
</html>
Same work done in another page with master page
2.jQueryGridview.aspx
<%# Page Title="" Language="C#" MasterPageFile="~/Site.master" AutoEventWireup="true" CodeFile="jQueryGridview.aspx.cs" Inherits="jQueryGridviewSortWithMasterPages" %>
<asp:Content ID="Content1" ContentPlaceHolderID="HeadContent" Runat="Server">
<style type="text/css">
th
{
cursor:pointer;
background-color:#dadada;
color:Black;
font-weight:bold;
text-align:left;
}
th.headerSortUp
{
background-image: url(images/asc.gif);
background-position: right center;
background-repeat:no-repeat;
}
th.headerSortDown
{
background-image: url(images/desc.gif);
background-position: right center;
background-repeat:no-repeat;
}
td
{
border-bottom: solid 1px #dadada;
}
</style>
<script src="../Scripts/jquery-1.4.1.min.js" type="text/javascript"></script>
<script src="../Scripts/jquery.tablesorter.min.js" type="text/javascript"></script>
<script type="text/javascript">
$.noConflict();
$(document).ready(function () {
$("#GridView1").tablesorter();
});
</script>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" Runat="Server">
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False"
DataKeyNames="RoleID" DataSourceID="SqlDataSource1">
<Columns>
<asp:BoundField DataField="RoleID" HeaderText="RoleID" InsertVisible="False"
ReadOnly="True" SortExpression="RoleID" />
<asp:BoundField DataField="RoleName" HeaderText="RoleName"
SortExpression="RoleName" />
<asp:CheckBoxField DataField="IsActive" HeaderText="IsActive"
SortExpression="IsActive" />
<asp:BoundField DataField="AddedBy" HeaderText="AddedBy"
SortExpression="AddedBy" />
<asp:BoundField DataField="AddedDate" HeaderText="AddedDate"
SortExpression="AddedDate" />
<asp:BoundField DataField="UpdatedBy" HeaderText="UpdatedBy"
SortExpression="UpdatedBy" />
<asp:BoundField DataField="UpdatedDate" HeaderText="UpdatedDate"
SortExpression="UpdatedDate" />
</Columns>
</asp:GridView>
<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="<%$ ConnectionStrings:WSMSConnectionString %>"
SelectCommand="SELECT [RoleID], [RoleName], [IsActive], [AddedBy], [AddedDate], [UpdatedBy], [UpdatedDate] FROM [Role]">
</asp:SqlDataSource>
<br />
</asp:Content>
both have code behind file
protected void Page_Load(object sender, EventArgs e)
{
GridView1.UseAccessibleHeader = true;
GridView1.HeaderRow.TableSection = TableRowSection.TableHeader;
}
The first(with out master page) is working but second one is not.
How to solve the problem?
i have solve it by using
ClientIDMode="Static"
in second GridView and rest is same.Then the html id will be
GridView1
and it works fine.
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False"
DataKeyNames="RoleID" DataSourceID="SqlDataSource1" ClientIDMode="Static">

Page_Load executing Twice

I know that this question has been asked before, but none of the remedies seem to be my solution.
I have an aspx page and a code behind with a Page_Load routine. My routine writes a record to a SQL table to capture the user's credentials.
The Page_Load has a !IsPostBack check, aspx has AutoEventWireup="True", and I have no img or any other element that would cause an AutoPostback to my knowledge. Still Page_Load is called twice.
Here is my .aspx page and the code behind. I am hoping someone can help.
<%# Page Language="C#" AutoEventWireup="true" CodeBehind="feedback.aspx.cs" Inherits="MEAU.Web.Components.SupportCenter.feedback" %>
<%# Import Namespace="Sitecore.Configuration" %>
<%# Import Namespace="Sitecore.Security.Accounts" %>
<%# Import Namespace="System.Data" %>
<%# Import Namespace="System.Data.SqlClient" %>
<!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">
<script type="text/javascript" src="/components/SupportCenter/design/js/jquery-1.8.1.min.js"></script>
<script type="text/javascript" src="/components/SupportCenter/design/js/jquery.easing.js"></script>
<script type="text/javascript" src="/components/SupportCenter/design/js/jquery.fancybox-1.3.4.pack.js"></script>
<script type="text/javascript" src="/components/SupportCenter/design/js/jquery.accordion.js"></script>
<script type="text/javascript" src="/components/SupportCenter/design/js/jquery.pngFix.js"></script>
<script type="text/javascript" src="/components/SupportCenter/design/js/global.js"></script>
<script type="text/javascript" src="/components/SupportCenter/design/js/jquery-tmpl.js"></script>
<head id="Head1" runat="server">
<style>
p.titlefont
{
font-family: "Arial" , Helvetica, Sans-Serif;
font-size:"12px";
}
</style>
<title>Feedback</title>
<script type="text/javascript">
function Init() {
var obj = window.dialogArguments;
var url = document.getElementById("url1");
var login = document.getElementById("login");
}
function getRadioValue(theRadioGroup) {
for (var i = 0; i < document.getElementsByName(theRadioGroup).length; i++) {
if (document.getElementsByName(theRadioGroup)[i].checked) {
return document.getElementsByName(theRadioGroup)[i].id;
}
}
}
function WriteToFile(sText) {
var fso = new ActiveXObject("Scripting.FileSystemObject");
var fo = fso.OpenTextFile('c:\\\inetput\\wwwwroot\LogFile.txt', 8, true, 0); // 8=append, true=create if not exist, 0 = ASCII
fo.WriteLine();
fo.Write(sText);
fo.Close();
}
</script>
</head>
<!--<body onload="javascript:Init();"> -->
<body>
<form id="form1" runat="server">
<div>
<p class="titlefont">
<asp:Literal ID="quest" Text="Did this resolve your issue?" runat="server" />
<br />
<br />
<asp:CheckBox ID="yes" runat="server" Text="Yes" Checked="true"
Font-Names="Arial" Font-Size="12px" /><br />
<asp:CheckBox ID="no" runat="server" Text="No" Font-Names="Arial"
Font-Size="12px" /><br />
<asp:Literal ID="lit" Text="Please select at least one answer" runat="server" Visible="false"/><br />
<asp:CheckBox ID="scall" runat="server" Text="Did this prevent a Service Call?" Visible="false" Font-Names="Arial"
Font-Size="12px" /><br />
<asp:CheckBox ID="parts" runat="server" Text="Did this prevent a Parts Shipment?" Visible="false"
Font-Names="Arial" Font-Size="12px" /><br />
<asp:CheckBox ID="wrnt" runat="server" Text="Is this under Warranty?" Font-Names="Arial" Visible="false"
Font-Size="12px" /><br />
<asp:CheckBox ID="none" runat="server" Text="None of the above" Font-Names="Arial" Visible="false"
Font-Size="12px" /><br />
<br />
<asp:Button ID="run" Text="SUBMIT" OnClick="Run_Write" runat="server" Font-Names="Arial"
Font-Size="12px" /><br />
<asp:Button ID="cancel" Text=" CANCEL " OnClick="Cancel_btn" runat="server" Font-Names="Arial"
Font-Size="12px" />
</p>
</div>
</form>
</body>
</html>
my code Behind:
protected void Page_Load(object sender, EventArgs e)
{
login = Sitecore.Security.Accounts.User.Current.Profile.Email;
myurl = Request.QueryString["value"];
if (!IsPostBack)
{
// Write a record and capture the User's credententials, even if they do not take an action
SqlConnection conn = new SqlConnection(Sitecore.Configuration.Settings.GetConnectionString("feedback"));
SqlCommand cmd = new SqlCommand("Insert_fb", conn);
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.AddWithValue("#login", login);
cmd.Parameters.AddWithValue("#url", myurl);
cmd.Parameters.AddWithValue("#response", "No");
cmd.Parameters.AddWithValue("#noResponse", "Yes");
cmd.Parameters.AddWithValue("#date", DateTime.Now);
cmd.Parameters.AddWithValue("#serviceCall", "No");
cmd.Parameters.AddWithValue("#partsShipment", "No");
cmd.Parameters.AddWithValue("#warranty", "No");
cmd.Parameters.AddWithValue("#cancel", "No");
cmd.Parameters.AddWithValue("#none", "No");
try
{
conn.Open();
cmd.ExecuteNonQuery();
}
catch (Exception ex)
{
throw new Exception("Error on file update" + ex.Message);
}
finally
{
conn.Close();
}
}
}

label.visible = true not working

The visible function doesnt work, but why? Is a true set in a callback not allowed?. When I set the visible to true on top of the page(_Default : System.Web.UI.Page) it is working.
information_remedyID.Visible = true;
information_remedyID.Text = inquiryId;
TOP Class:
public partial class _Default : System.Web.UI.Page
{
.......
private static string inquiryId;
......
private void InsertIncidentCallback(server3.ILTISAPI api, IAsyncResult result, string username, string msg_id)
{
string message;
api.EndInsertIncident(result, out message);
if (message == null)
{
string responseXML;
api.REMEDY_ReadResponseXML(username, out responseXML, out msg_id);
XDocument doc = XDocument.Parse(responseXML);
inquiryId = (string)doc.Root.Element("inquiry_id");
if (inquiryId == null | inquiryId == "")
{
information_text.Text = "....";
}
else
{
information_remedyID.Visible = true;
information_remedyID.Text = inquiryId;
//create_LanDesk(computer_idn, swidn_choice, swName_choice, inquiryId);
}
}
else
{
information_text.Visible = true;
information_text.Text = "...";
}
}
}
asp:
<%# Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_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 id="Head1" runat="server">
<title>Willkommen im BISS</title>
</head>
<body>
<form id="form1" runat="server">
<span style="font-size: 16pt"><strong>BISS<br />
</strong><span style="font-size: 12pt">
<br />
Angemeldet als:
<asp:Label ID="user_id" runat="server" Text="user_id"></asp:Label><br />
Hostname:
<asp:Label ID="hostname_id" runat="server" Text="hostname_id"></asp:Label>
<br />
CI Nummer:
<asp:Label ID="CI_NR" runat="server" Text="CI_NR"></asp:Label></span></span>
<br />
<br />
<asp:DropDownList ID="softwarelist" runat="server" DataTextField="SoftwareName" DataValueField="SoftwareName">
<asp:ListItem Text="Bitte Software auswählen" Value=""></asp:ListItem>
</asp:DropDownList>
<asp:Button ID="requestbt" runat="server" OnClick="Button1_Click" Text="Software zuweisen" /><br />
<asp:Label ID="information_text" runat="server" Text="information_text" Visible="False"></asp:Label><br />
<asp:Label ID="information_remedyID" runat="server" Text="information_remedyID" Visible="False"></asp:Label>
<br />
</form>
</body>
</html>
Do you use a UpdatePanel with UpdateMode="Conditional"
<asp:UpdatePanel ID="ProfileEditingUpdatePanel" runat="server" UpdateMode="Conditional">
In case you use WPF
information_remedyID.Visibility = Visibility.Visible;
Sorry, overread ASP!
if (inquiryId == null | inquiryId == "")
If this should be an or change it to a double stripe:
if (inquiryId == null || inquiryId == "")
Use a UpdatePanel, like this:
<%# Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_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 id="Head1" runat="server">
<title>Willkommen</title>
</head>
<body>
<form id="form1" runat="server">
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<asp:UpdatePanel ID="MyUpdatePanel" runat="server" UpdateMode="Conditional">
<ContentTemplate>
<span style="font-size: 16pt">
<strong>
BISS<br />
</strong>
<span style="font-size: 12pt">
<br />
Angemeldet als:
<asp:Label ID="user_id" runat="server" Text="user_id"></asp:Label><br />
Hostname:
<asp:Label ID="hostname_id" runat="server" Text="hostname_id"></asp:Label>
<br />
CI Nummer:
<asp:Label ID="CI_NR" runat="server" Text="CI_NR"></asp:Label></span></span>
<br />
<br />
<asp:DropDownList ID="softwarelist" runat="server" DataTextField="SoftwareName" DataValueField="SoftwareName">
<asp:ListItem Text="Bitte Software auswählen" Value=""></asp:ListItem>
</asp:DropDownList>
<asp:Button ID="requestbt" runat="server" OnClick="Button1_Click" Text="Software zuweisen" /><br />
<asp:Label ID="information_text" runat="server" Text="information_text" Visible="False"></asp:Label><br />
<asp:Label ID="information_remedyID" runat="server" Text="information_remedyID" Visible="False"></asp:Label>
<br />
</ContentTemplate>
</asp:UpdatePanel>
</form>
</body>
</html>
And in your code, after you changed the visibility:
MyUpdatePanel.Update();
I couldn't get this to work either.
A workaround is to use Style="display: none;" instead of Visible="False". Then you can reveal it with
information_remedyID.Style["display"] = "initial";

Problem with ajax tabcontainer

i use from ajax tabcontainer .and i want to when value of hiddenfield is not 1(value of hiddenfield change when i click in gridview,i dont have problem with set value for hiddenfield) and user click in email tab it alerts and stays in first tab.but in my code it alert and changes tab.i want to stay in cuurent tab.
i write this code but it dosent work.
please help me.
<%# Page Language="C#" %>
<%# Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="asp" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org
<script type="text/javascript">
function SetActiveTab() {
var hfd = $get('<%=HiddenField1.ClientID%>');
if (hfd.value != "1") {
alert("hitttttttt");
var ctrl = $find('TabContainer1');
ctrl.set_activeTab(ctrl.get_tabs()[0]);
}
}
</script>
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
<title>Ajax Control - Tabs </title>
</head>
<body>
<form id="form1" runat="server">
<b>Tabs Demonstration</b> <br />
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<asp:HiddenField ID="HiddenField1" runat="server" />
<br />
<asp:TabContainer runat="server" ID="TabContainer1" Height="138px" ActiveTabIndex="0"
Width="402px">
<asp:TabPanel runat="server" ID="Panel1" HeaderText="Address" >
<ContentTemplate>
<asp:UpdatePanel ID="updatePanel1" runat="server">
<ContentTemplate>
<table>
<tr><td>First Name:</td><td><asp:TextBox ID="txtName" runat="server" /></td></tr>
<tr><td>Address:</td><td><asp:TextBox ID="txtAddress" runat="server" /></td></tr>
</table>
</ContentTemplate>
</asp:UpdatePanel>
</ContentTemplate>
</asp:TabPanel>
<asp:TabPanel runat="server" ID="Panel3" HeaderText="Email" OnClientClick="SetActiveTab" >
<ContentTemplate>
Email: <asp:TextBox ID="txtEmail" runat="server" />
</ContentTemplate>
</asp:TabPanel>
<asp:TabPanel runat="server" ID="Panel2" HeaderText="Login Details" >
<ContentTemplate>
<table>
<tr> <td>User Name:</td><td><asp:TextBox ID="txtUser" runat="server" /></td></tr>
<tr> <td>Password:</td><td><asp:TextBox ID="txtPass" runat="server" /></td></tr>
</ContentTemplate>
</asp:TabPanel>
</asp:TabContainer>
</form>
The one solution I found is to remove OnClientClick handler and use the javascript below:
function pageLoad() {
var tabContainer = $find('<%= TabContainer1.ClientID %>');
var hfd = $get('<%= HiddenField1.ClientID %>');
var oldSetActiveTab = Function.createDelegate(tabContainer, tabContainer.set_activeTab);
tabContainer.set_activeTab = function (value) {
if (value.get_id() == '<%= Panel3.ClientID %>' && hfd.value != "-1") {
alert("oops");
}
else {
oldSetActiveTab(value);
}
};
}

How to access controls in a list view row

I have listview and every row has a Drop Down List and a hyperlink control.
What i'm trying to do is change the navigate url for the hyperlink based on the selection of the drop down list. How would I get the row that the control posted back from so I can find the hyperlink control?
You may try the following:
<%# Page Language="C#" %>
<script type="text/C#" runat="server">
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
MyList.DataSource = Enumerable.Range(1, 5);
MyList.DataBind();
}
}
protected void DDLChange(object sender, EventArgs e)
{
var ddl = (DropDownList)sender;
var link = (HyperLink)ddl.Parent.FindControl("MyLink");
link.NavigateUrl = ddl.SelectedValue;
link.Text = ddl.SelectedValue;
}
</script>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head id="Head1" runat="server">
<title></title>
</head>
<body>
<form id="Form1" runat="server">
<asp:ListView ID="MyList" runat="server">
<ItemTemplate>
<div>
<asp:DropDownList runat="server" AutoPostBack="true" OnSelectedIndexChanged="DDLChange">
<asp:ListItem Value="http://www.google.com" Text="http://www.google.com" />
<asp:ListItem Value="http://www.bing.com" Text="http://www.bing.com" />
<asp:ListItem Value="http://www.yahoo.com" Text="http://www.yahoo.com" />
</asp:DropDownList>
<asp:HyperLink runat="server" ID="MyLink" NavigateUrl="http://www.google.com" Text="http://www.google.com" />
</div>
</ItemTemplate>
</asp:ListView>
</form>
</body>
</html>

Categories