Solved

Open form from Gridview edit button

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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Sometimes in DotNetNuke module development you want to swap controls within the same module definition.  In doing this DNN (somewhat annoyingly) swaps the Skin and Container definitions to the default admin selections.  To get around this you need t…
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…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

757 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

20 Experts available now in Live!

Get 1:1 Help Now