?
Solved

Open form from Gridview edit button

Posted on 2011-09-28
1
Medium Priority
?
301 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment
 
LVL 28

Accepted Solution

by:
strickdd earned 2000 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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

IntroductionWhile developing web applications, a single page might contain many regions and each region might contain many number of controls with the capability to perform  postback. Many times you might need to perform some action on an ASP.NET po…
Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …
Suggested Courses

801 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