Tech
Forums
Jobs
Books
Events
Interviews
Live
More
Learn
Training
Career
Members
Videos
News
Blogs
Post
An Article
A Blog
A Video
An Ebook
An Interview Question
Register
Login
0
Reply
GridView row data Shown in FormView. Change Mode & Save data
Terry
9 years ago
563
Reply
Hello,
In ASP.NET WebForms app, I have a Gridview whose data is shown in From View when a row is selected from the GridView. I have New, Save, Edit & Cancel buttons outside Grid & Form View's.
My FormView in aspx :
<asp:FormView ID="inqFormView" runat="server" DataKeyNames="Id"
ItemType="VincitoreCRMApplication.Models.Inquiry" DefaultMode="ReadOnly"
Width="100%" Height="206px" CssClass="panel panel-default"
style="background-color: white; border-radius:8px; margin-top:-1px;"
OnModeChanging="inqFormView_ModeChanging" >
I am facing couple of problems & queries regarding the buttons & actions on Form View :
In my editBtn, I change the Mode of FormView to Edit, but it is not changing - it remains in ItemTemplate only. MY code of editBtn :
protected void editInquiryBtn_Click(object sender, EventArgs e)
{
newInquiry.Visible = false;
editInquiry.Visible = false;
saveInquiry.Visible = true;
cancelBtn.Visible = true;
TaskTitle = "Update Inquiry Details";
//Tried to set item to be edited in FormView
inqFormView_GetItem(5);
inqFormView.ChangeMode(FormViewMode.Edit);
// inqFormView.DataBind(); // IF I ENABLE THIS LINE, THEN NO DATA IS SHOWN
saveInquiry.CommandArgument = EditArgs;
return;
}
Once able to edit, user clicks o the "Save" btn (that is outside of Grid & Form Views') I want to someway fire the Update call of FormView & the data gets updated.
I have an EmptyDataTemplate in FromView, with just empty text boxes. When their is no data, the FromView is just hidden (not visible). I want the form to be seen when when their is no data. For this, in Page_Load, in is(! IsPostback ) , I am calling
inqFormView_GetItem(-1);
public Inquiry inqFormView_GetItem(int id)
{
// If their i no item of the id passed, adds an empty item and sends it. But it doesn't work
Inquiry item = new Inquiry();
item.Id = 0;
List<Inquiry> items = _db.Inquiries.Where(s => s.Id == id).ToList<Inquiry>();
if (items.Count > 0)
{
item = items[0];
}
else
items.Add(item);
return item;
}
For ModeChanging, I added the event also, but that is never fired at all :
protected void inqFormView_ModeChanging(object sender, FormViewModeEventArgs e)
{
inqFormView.ChangeMode(e.NewMode);
inqFormView.DataBind();
}
Can you please help me with these problems and guide me achieve the goal.
Any help is highly appreciated.
Thanks.
Post
Reset
Cancel
Answers (
0
)
Next Recommended Forum
The resource cannot be found in asp.net error
Entity framework 6.1.3 Code first many to many relationship