Solved

Open form from Gridview edit button

Posted on 2011-09-28
1
298 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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

In this Article, I will provide a few tips in problem and solution manner. Opening an ASPX page in Visual studio 2003 is very slow. To make it fast, please do follow below steps:   Open the Solution/Project. Right click the ASPX file to b…
I recently went through the process of creating a Calendar Control of events with the basis of using a database to keep track of the dates that are selectable, one requirement was to have the selected date pop-up in a simple lightbox.  At first this…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…

679 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