Solved

Open form from Gridview edit button

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

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

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

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…
Introduction This article shows how to use the open source plupload control to upload multiple images. The images are resized on the client side before uploading and the upload is done in chunks. Background I had to provide a way for user…
Windows 10 is mostly good. However the one thing that annoys me is how many clicks you have to do to dial a VPN connection. You have to go to settings from the start menu, (2 clicks), Network and Internet (1 click), Click VPN (another click) then fi…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

813 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

14 Experts available now in Live!

Get 1:1 Help Now