Update other controls after a Postback has fired from another control - eg insert data - display in gridview


This is a slight modification to the personalweb asp.net template which shipped with VS2005

I have a web form - linked to a master with two content placeholders left and right:

#1 In the left i have a formview containing a textbox + button - and a datasrouce object with an insertmethod - this calls a method to insert the textbox data into table albums:

#2 In the right  i have a gridview which has a datasource this has a selectmethod which calls a select method from table albums.

Because i am using a maser template with two content placeholders i cannot use the same ObjectDataSource. So i have two - this is where the probelm arises where - adding a record does not show in the gridview which is bound to the other datasource.

Can i share the datasources between both controls - to avoid an error message such as:

The DataSourceID of 'FormView1' must be the ID of a control of type IDataSource.  A control with ID 'ObjectDataSource1' could not be found.


Update one on a postback etc 


I realise - i could move the formview into the same ContentPlaceHolderID as the gridview and then it works -but that wastn the plan!



The gridview wroks as planned and displays a list of albums:

When i click the insert button in #1 the insert takes place - the gridview does not show the updated table table - which is correct behaviour at that point.

A page refresh without resending the postback data e.g navigate to the same url via a link - will show the new data. 

I would like to force the gridview to refresh its data - after the user has clicked the insert button and executed the insert.


<%@ Page Language="C#" MasterPageFile="~/LeftNavColContent.master" Title="Albums| Admin"
    CodeFile="Albums.aspx.cs" Inherits="Admin_Albums_aspx" EnableViewState="false"   %>

<asp:Content ID="Content1" ContentPlaceHolderID="Main" runat="server">
        Your Albums</h2>
        The following are the albums currently on your site. Click <b>Edit</b> to modify
        the pictures in each album. Click <b>Delete</b> to permanently remove the album
        and all of its pictures</p>
    <asp:GridView ID="GridView1" runat="server" DataSourceID="ObjectDataSource1" DataKeyNames="AlbumID"
        CellPadding="6" AutoGenerateColumns="False" BorderStyle="None" BorderWidth="0px"
        Width="420px" ShowHeader="false" EnableViewState="false" AllowPaging="true">
            You currently have no albums.
        <EmptyDataRowStyle CssClass="emptydata"></EmptyDataRowStyle>
                <ItemStyle Width="116" />
                    <table border="0" cellpadding="0" cellspacing="0" class="photo-frame">
                            <td class="topx--">
                            <td class="top-x-">
                            <td class="top--x">
                            <td class="midx--">
                                <a href='Photos.aspx?AlbumID=<%# Eval("AlbumID") %>'>
                                    <img src="../Handler.ashx?AlbumID=<%# Eval("AlbumID") %>&amp;Size=S" class="photo_198"
                                        style="border: 4px solid white" alt="Sample Photo from Album Number <%# Eval("AlbumID") %>" /></a></td>
                            <td class="mid--x">
                            <td class="botx--">
                            <td class="bot-x-">
                            <td class="bot--x">
                <ItemStyle Width="280" />
                    <div style="padding: 8px 0;">
                            <%# Server.HtmlEncode(Eval("Caption").ToString()) %>
                        <br />
                        <%# Eval("Count") %>
                        Photo(s)<asp:Label ID="Label1" runat="server" Text=" Public" Visible='<%# Eval("IsPublic") %>'></asp:Label>
                    <div style="width: 100%; text-align: right;">
                        <asp:ImageButton ID="ImageButton2" runat="server" CommandName="Edit" SkinID="rename" />
                        <a href='<%# "Photos.aspx?AlbumID=" + Eval("AlbumID") %>'>
                            <asp:Image ID="Image1" runat="Server" SkinID="edit" /></a>
                        <asp:ImageButton ID="ImageButton3" runat="server" CommandName="Delete" SkinID="delete" />
                    <div style="padding: 8px 0;">
                        <asp:TextBox ID="TextBox2" runat="server" Width="160" Text='<%# Bind("Caption") %>'
                            CssClass="textfield" />
                        <asp:CheckBox ID="CheckBox1" runat="server" Checked='<%# Bind("IsPublic") %>' Text="Public" />
                    <div style="width: 100%; text-align: right;">
                        <asp:ImageButton ID="ImageButton4" runat="server" CommandName="Update" SkinID="save" />
                        <asp:ImageButton ID="ImageButton5" runat="server" CommandName="Cancel" SkinID="cancel" />
    <asp:ObjectDataSource ID="ObjectDataSource1" runat="server" TypeName="PhotoManager"
        SelectMethod="GetAlbums" InsertMethod="AddAlbum" DeleteMethod="RemoveAlbum" UpdateMethod="EditAlbum" EnableViewState="false" >
<asp:Content ID="Content4" ContentPlaceHolderID="leftColumn" runat="Server">
        Add New Album</h2>
        Before uploading your pictures, create an album to organize your pictures.</p>
    <asp:FormView ID="FormView1" runat="server" DataSourceID="ObjectDataSource2" DefaultMode="Insert"
        BorderWidth="0" CellPadding="0" EnableViewState="false" >
            <asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ErrorMessage="You must choose a    title."
                ControlToValidate="TextBox1" Display="Dynamic" Enabled="false" />
                Title<br />
                <asp:TextBox ID="TextBox1" runat="server" Width="200" Text='<%# Bind("Caption") %>'
                    CssClass="textfield" />
                <asp:CheckBox ID="CheckBox2" runat="server" Checked='<%# Bind("IsPublic") %>' Text="Make this album public" />
            <p style="text-align: left;">
                <asp:ImageButton ID="ImageButton1" runat="server" CommandName="Insert"  SkinID="add"  />
    <asp:ObjectDataSource ID="ObjectDataSource2" runat="server" TypeName="PhotoManager"

**********************************CODE BEHIND*******************************************

using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

public partial class Admin_Albums_aspx : System.Web.UI.Page {

    protected void Page_Load(object sender, EventArgs e)

        if (IsPostBack)
            //if album added then update gridview



8/28/2007 3:17:39 PM
asp.net.presentation-controls 72751 articles. 3 followers. Follow

2 Replies

Similar Articles

[PageSpeed] 33


  Please try this:

  protected void FormView1_ItemInserted(object sender, FormViewInsertedEventArgs e)


Allen Chen
Microsoft Online Community Support

Please remember to mark the replies as answers if they help and unmark them if they provide no help.
8/30/2007 6:59:17 AM

 Yup that works!

 Now i got to work why the heck i didn't try that in the first place! 

Many thanks!



8/31/2007 1:05:22 PM

Similar Artilces:

Data presentation control in another Data presentation control
 Hello,I want to make a menu with datalist or gridview control.Basically,the menu will be like this,Categories     Sub Categories.For example, for COMPUTING category there will be NOTEBOOKS DESKTOPS etc.There will be a image for CATEGORIES and linkbuttons with Subcategories.If I put a datalist inside a datalist and a link button inside the second datalist visually it satisfies my need.However,CommandArguments come from database to linkbutton.Andwhen one of these command buttons is cliked it must go to proper page.I dont know how to wrie an event_handler ,specifically, for...

How do I control one control from another control?
I have a page page1.aspx which is within a master page. On page I have a table with two cells. Within each cell I have placed two controls (ascx) that I have developed. Now I'd like to be able to get these two controls to interact. One needs to update the other. One has some search criteria that the other one needs to update its gridview. One needs to make the other visible/not visible at certain times. Out of the box neither control can see each other at all. Is there a good article or someplace I can find some information on how to do this?  AllAboutFocus.com. Information Technolo...

gridview control in another gridview control
Hi ia have a questioni have a gridview control which contains button in one colum.now my question is i need another gridview to be placed in the  first gidviewso that when i click on the button the second gridview will populate the data.now my question is how to place second gridview in first gridview.or is there any approach like first grid itself acting as parent and child.please help me  Hi sirikalavalapalli:                I think nested gridview will help you. Check this link and it will show you how...

Updating a Label control in one user control from another user control
Hi all, I have a main page in my music store site that has 5 user controls on it with 1 always showing main content and the others being things like a shopping cart, "best sellers", genre list etc (a la amazon). From the main content control I want to be able to set some label controls in my shopping basket control but I just can't seem to work out the syntax for how to do this: Here's the code I'm using - I'm trying to go to the 4th user control on the page (my shopping basket) then find the appropraite label, cast it locally as a Label then update the value: Label _so...

Edit data with GridView Control ? or another control ? help
I use GrivView in ASP.Net 2.0 to show data from DataTable. And i want to edit some fields in some rows. How can I do it? If i touch EDIT button - all columns, which have ReadOnly=false, switch into EDIT mode. But I want, that in first raw I can edit 2,3 column and in second row only 3 column. How can I do it ? ...

Using Data Control in another data control
Hey, How to use a SqlDataSource control in a GridView and so on...I mean i wanna show data which comes from UserTables in a gridview whoses data comes from ContentTable so they are two separated tables. Thanks and Regards...I am not a perfect programmer, but i have perfect programmers' habits [ i think so :)] I mean how to use nested gridview controls. Please aren't there any poeple who can help me ?I am not a perfect programmer, but i have perfect programmers' habits [ i think so :)] Try the links below, they might be of some help to you.http://msdn2.microso...

Gridview control embedded in another gridview control
I am writing an ambulance crew scheduling application on the web and I need some help completing the last part.  I have an access database that has three tables: user table, shift table (describing the shifts available), and a schedule table (that stores shift by shift_id and user by user_id).  I have a gridview control that will display the available shifts but I cannot get the embedded gridview control that will display the user that is signed up for each shift to display because I cannot figure out how to use the OnRowDataBound method.  I need a simple VB example of how to...

Trying to load a control into a control from another control
Exactly as the subject states, I'm trying to load a control into another control from a control loaded into a page, I keep getting this error from the code I have below. I've also tried the findcontrol but it keeps coming up null. (67): 'System.Web.UI.UserControl' denotes a 'class' where a 'variable' was expected UserControl ut = ((webcontrols.BrowseItems)UserControl).LoadControl("BrowseItems"); ((webcontrols.BrowseItems)UserControl).pnl_browse_main.Controls.Add(ut); This is how we Load User controls into a content place holder. try { UserCont...

There is a Gridview Control in the tmplate field of another GridView Control.
    For instance,a gridview displays the information of the  students in a class.A table is recording the information except their mark.There is another table recording the mark of the students whose foreign key is the primary key of the previous table.   string strSQLconnection=".................."; SqlConnection sqlCononection=new SqlConnection(strSQLconnection); SqlCommand sqlCommand=new SqlCommand("select * from stuendent where classID=1",sqlConnection); SqlConnection.Open(); SqlDataReader reader=sqlCommand.ExecuteReader(); GridVie...

Bind Data to an Image Control not in a Data Presentation Control
I've been searching for two days but I don't really know what to search for.I'm making a site for a photographer.  The Default.aspx page displays Albums by showing a title, image and description from the database table Albums. Click an album to view the contents and it passes the QueryString which is AlbumName.  The ViewAlbum.aspx page uses the QueryString to display an UpdatePanel holding a Large Image and a Repeater full of dynamically filled ImageButtons for thumbs.  Both are from the database table Photos and are retrieved using an ObjectDataSource. Click the ...

Trying to use the FAQ " Sorting and paging in the GridView control when not using data source controls "Sorting and paging in the GridView control when not using..."
and I am not getting the results I had hoped for.  I keep getting a "Compiler Error Message: CS0123: No overload for 'AdhocJobGridView_PageIndexChanged' matches delegate 'System.EventHandler'".   Here is my event handling... protected void AdhocJobGridView_PageIndexChanged(object sender, GridViewPageEventArgs e){ try { AdhocJobGridView.DataSource = wsBaseInfoArray; AdhocJobGridView.PageIndex = e.NewPageIndex; AdhocJobGridView.DataBind(); }catch (Exception ex) {throw ex; }   Here is my aspx... <asp:GridView ID="AdhocJobGridView...

ajax control in data presentation controls
can i add ajax controls (MaskedEdit) to presentation controls (dataGrid, dataForm)?? Hi,of course. But keep in mind that those controls are extenders, so you append them to an existing control. Just convert your GridView / DetailsView-fields into templated fields and add the extender you'd like to use to the controls.RegardsMarco Buerckel Don't forget to mark posts that were helpful as answers. Actually, if you looked at the source code for the Masked Edit Extender, you'd see  [TargetControlType(typeof(TextBox))]Meaning, targeting any control type other than textboxes...

Controls.Add in Composite Control that inherits another control
Hi! I created a composite control that inherits from the WebControls.Button. I added the following in the Load event:         Dim mHidden As New WebControls.HiddenField        Me.Controls.Add(mHidden) but the control is not created. Why?Dimitris PapadimitriouSoftware Development Professional Hi,Child controls on Button do not make much sense (how would you expect them to be rendered, doesn't button allow only text into value attribute?). Button allows child controls to be added, but they won't be rendered b...

Getting the control id of a control inside gridview control
 uhmm.. a little bit confusing regarding my subject because i dont know how to say it...by the way my problem is how can i get the id of a control (e.g. textbox) inside the gridview... and the textbox is in the templatefield... is there any way i can get its id??  hoping i could get a reply as soon as possible... Regards,MhaeyPlease remember to click “Mark as Answer” on the post that helps you.. =) What do you want's to do by getting the id of the Text box? Do you want's to find particular Textbox with certain id ? Kamran ShahidSr. Software Engineer(MCP,MCAD.net,MC...

Visibility control of Panel control and its affect on data controls
Thought I would toss this out here this morning and perhaps someone else had run across the same issue and had found a good way to accomplish what I want. First let me state what I'm attempting to do and the problem that I've run into.  GridView1 has a collection of rows in a SQL table that I want to present to the user. I've provided them the options of sorting and selecting only from the GridView control.  Orgionally, I had created a detail view that was being presented in Edit mode and then customized the layout of the edit item template to suit my needs.&nbs...

Web resources about - Update other controls after a Postback has fired from another control - eg insert data - display in gridview - asp.net.presentation-controls

Control - Wikipedia, the free encyclopedia
Text is available under the Creative Commons Attribution-ShareAlike License ;additional terms may apply. By using this site, you agree to the ...

US Democratic candidates clash over gun control at debate
Hillary Clinton criticised over foreign policy and gun control but again confirms her position as frontrunner for the Democratic nomination. ...

Victorian fires out of control
Residents are being urged to evacuate as an out of control bushfire near the Indigo Valley in northern Victoria threatens homes. Courtesy ABC ...

As it happened: Fire crews battle out-of-control blazes in southern states
Emergency warnings are in place for a fire burning in Victoria's north-east while fire crews also tackle blazes in ACT, NSW and Tasmania.

Dell Issues Patch For Content Adaptive Brightness Control On The XPS 13
... issues, as all devices do. One that was very frustrating to deal with during the review was the aggressive Content Adaptive Brightness Control ...

Taliban forces take control of key district in Afghanistan's Helmand province
CNN Taliban forces take control of key district in Afghanistan's Helmand province CNN Kabul, Afghanistan (CNN) Taliban forces have taken almost ...

Taliban take control of Afghanistan's Helmand province - CNN.com
Taliban forces have taken almost full control of a key district in Afghanistan's southern Helmand province after several days of fierce fighting. ...

NRA: 6.3 Million Concealed Carry Permit Holders Affected By Virginia Gun Control Move
The National Rifle Association says 6.3 million concealed carry permit holders will be affected by Virginia’s Democrat Attorney General’s move ...

How Sepp Blatter Lost Control Of His Monster
If Sepp Blatter could take a step back and look at the bigger picture, forgetting for a moment that today’s eight-year ban from all soccer activities ...

This is what Street Fighter IV looks like with motion controls
Like most people it seems, I think that the Steam Controller has potential, but it just hasn't been realized yet. It's a great time to test ...

Resources last updated: 12/23/2015 1:00:21 AM