Solved

Open form from Gridview edit button

Posted on 2011-09-28
1
289 Views
Last Modified: 2012-06-21
I'm trying to open a form from a grdivie edit button. It's a simple gridview, with edit and delete buttons. When you click the edit button, another form will pop up to let you edit the selected record from the grid. This is what I have, but it gives me a server tag is not well formed error.
<asp:Button ID="EditLeg" runat="server" Text="Edit" OnClick="openItin('Itinerary.aspx?id=<%# Eval("PKey") %>');"></asp:Button>
Any help is appreciated.
0
Comment
Question by:dodgerfan
1 Comment
 
LVL 28

Accepted Solution

by:
strickdd earned 500 total points
ID: 36719668
Here is an example of how I acheive this. I haven't cleaned it up at all, but the concept is there.

<asp:MultiView ID="MainMultiView" runat="server" ActiveViewIndex="0">
<asp:View ID="GridListView" runat="server">
	<asp:GridView ID="QueueAnswerGrid" runat="server" AutoGenerateColumns="False" AllowSorting="True" OnRowCommand="QueueAnswerGrid_RowCommand" DataSourceID="QueueAnswerData" DataKeyNames="ID">
		<Columns>
			<asp:BoundField DataField="AnswerText" HeaderText="AnswerText" SortExpression="AnswerText" />
			<asp:CheckBoxField DataField="Active" HeaderText="Active" SortExpression="Active" />
			<asp:CheckBoxField DataField="CausesStop" HeaderText="CausesStop" SortExpression="CausesStop" />
			<asp:ButtonField ButtonType="button" Text="Edit" CausesValidation="false" CommandName="EditRow" ItemStyle-HorizontalAlign="center" />
		</Columns>
		<EmptyDataTemplate>
			<b>This queue does not have any associated questions.</b>
		</EmptyDataTemplate>
	</asp:GridView>
	<asp:ObjectDataSource ID="QueueAnswerData" runat="server" OldValuesParameterFormatString="original_{0}" SelectMethod="GetQueueAnswers" TypeName="QueueDataTableAdapters.QueueAnswerTableAdapter">
		<SelectParameters>
			<asp:QueryStringParameter Name="QuestionID" QueryStringField="QueueQuestionID" Type="Int32" />
		</SelectParameters>
	</asp:ObjectDataSource>
</asp:View>
<asp:View ID="ItemView" runat="server">
	
	<div class="DataSeparator">
		<b>Answer Text:</b>
		<div class="DataField">
			<asp:TextBox ID="AnswerText" runat="server" Columns="100" MaxLength="100" />
			<asp:RequiredFieldValidator ID="AnswerTextValid" runat="server" ControlToValidate="AnswerText" Display="dynamic" Text="Required" />
		</div>
	</div>
	
	<div class="DataSeparator DataField">
		<asp:CheckBox ID="IsActive" runat="server" Font-Bold="true" Text="Active" />
	</div>
	
	<div class="DataSeparator DataField">
		<asp:CheckBox ID="CausesStop" runat="server" Font-Bold="true" Text="Causes Stop" />
	</div>
	
	<div class="DataSeparator">
		<b>Note Text:</b>
		<div class="DataField">
			<asp:TextBox ID="NoteText" runat="server" Columns="100" MaxLength="100" />
			<asp:RequiredFieldValidator ID="NoteTextValid" runat="server" ControlToValidate="NoteText" Display="dynamic" Text="Required" />
		</div>
	</div>
	
	<div class="DataSeparator">
		<b>Named Answer:</b>
		<div class="DataField">
			<asp:Label ID="NamedAnswer" runat="server" />
		</div>
	</div>
	
	<div class="DataSeparator">
		<b>Script Text:</b>
		<div class="DataField">
			<asp:TextBox ID="ScriptText" runat="server" Columns="100" Rows="5" />
		</div>
	</div>
		
	<div class="SubmitButtons">
		<div style="width: 500px; margin:auto;">
			<asp:Button ID="SubmitButton" runat="server" Text="Save Changes" OnClick="SubmitButton_Click" />
			&nbsp;&nbsp;
			<asp:Button ID="CancelButton" runat="server" Text="Cancel Changes" OnClick="CancelButton_Click" CausesValidation="false" />
		</div>
	</div>
	
</asp:View>
</asp:MultiView>
<asp:Literal ID="MessageLiteral" runat="server" EnableViewState="false" />
<br />		
<br />

<asp:HiddenField ID="IDHF" runat="server" />

Open in new window


 protected void Page_Load(object sender, EventArgs e)
    {
		if (String.IsNullOrEmpty(Request.QueryString["QueueID"]))
		{
			Response.Redirect("Queues.aspx");
		}
		else if (String.IsNullOrEmpty(Request.QueryString["QueueQuestionID"]))
		{
			Response.Redirect("QueueQuestions.aspx?QueueID=" + Request.QueryString["QueueID"]);
		}
		Master.PageHeader = "Queue Answer Management";

		if (!Page.IsPostBack)
		{
			PopulateQueueQuestion();
		}
	}

	#region Control Events
	protected void BackButton_Click(object sender, EventArgs e)
	{
		Response.Redirect("QueueQuestions.aspx?QueueID=" + Request.QueryString["QueueID"]);
	}

	protected void SubmitButton_Click(object sender, EventArgs e)
	{
		if (Page.IsValid)
		{
			SaveData();

			ResetPage();
		}
	}

	protected void CancelButton_Click(object sender, EventArgs e)
	{
		ResetPage();
	}

	protected void QueueAnswerGrid_RowCommand(object sender, GridViewCommandEventArgs e)
	{
		if (e.CommandName == "EditRow")
		{
			IDHF.Value = ((GridView)sender).DataKeys[ConvertObject.ToInt(e.CommandArgument)].Value.ToString();
			PopulateDataByID();
			MainMultiView.SetActiveView(ItemView);
		}
	}

	#endregion

	#region Private Methods
	private void PopulateQueueQuestion()
	{
		QueueQuestion.InnerHtml = new QueueDataTableAdapters.QueueQuestionTableAdapter().GetQueueQuestionByQuestionId(ConvertObject.ToInt(Request.QueryString["QueueQuestionID"]))[0].Question_Text;
	}

	private void PopulateDataByID()
	{
		QueueData.QueueAnswerDataTable queueAnswerInfo = new QueueDataTableAdapters.QueueAnswerTableAdapter().GetQueueAnswerByAnswerId(ConvertObject.ToInt(IDHF.Value));
		QueueData.QueueAnswerRow row;

		if (queueAnswerInfo.Rows.Count > 0)
		{
			row = queueAnswerInfo[0];

			AnswerText.Text = row.AnswerText;
			NoteText.Text = (row.IsNoteTextNull() ? "" : row.NoteText);
			IsActive.Checked = row.Active;
			CausesStop.Checked = row.CausesStop;
			NamedAnswer.Text = (row.IsNamedAnswerNull() ? "<i>None</i>" : row.NamedAnswer);
			ScriptText.Text = (row.IsScriptTextNull() ? "" : row.ScriptText);
		}
		else
		{
			MessageLiteral.Text = "<span style='color:Red;'>An error occurred retrieving record information.</span>";
		}
	}

	private void ResetPage()
	{
		IDHF.Value = "";
		MainMultiView.SetActiveView(GridListView);
		QueueAnswerGrid.DataBind();
	}

	private void SaveData()
	{
		new QueueDataTableAdapters.QueueAnswerTableAdapter().UpdateQueueAnswer(ConvertObject.ToInt(IDHF.Value), AnswerText.Text, NoteText.Text, IsActive.Checked, CausesStop.Checked, ScriptText.Text, SessionVariables.RACF);
	}
	#endregion

Open in new window

0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article discusses the ASP.NET AJAX ModalPopupExtender control. In this article we will show how to use the ModalPopupExtender control, how to display/show/call the ASP.NET AJAX ModalPopupExtender control from javascript, how to show/display/cal…
In .NET 2.0, Microsoft introduced the Web Site.  This was the default way to create a web Project in Visual Studio 2005.  In Visual Studio 2008, the Web Application has been restored as the default web Project in Visual Studio/.NET 3.x The Web Si…
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.
This is a video that shows how the OnPage alerts system integrates into ConnectWise, how a trigger is set, how a page is sent via the trigger, and how the SENT, DELIVERED, READ & REPLIED receipts get entered into the internal tab of the ConnectWise …

919 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now