Ask a Question related to ASP.NET Data Grid Control, Design and Development.

  1. #1

    Default Refreshing datagrid

    Hi all...
    I have an asp page with a datagrid, and a imagebutton to add a new row.
    every time I click that new button, a new page appear and user can entry
    data, save and close that page.
    the problem is :
    I want my datagrid reflecting the changes of my add new row, so every time I
    save and close that add new record page,
    automatically it add a new row in my datagrid

    thank

    ruby


    Ruby Guest

  2. Similar Questions and Discussions

    1. .asr pages not refreshing?
      I have a Flash cfform that has ActionScript the includes a "#include 'my_asr_page.asr'" statement. My .asr page works fine with the form, but when I...
    2. Templates not refreshing
      When I make updates to a template in Dreamweaver, and then attempt to create a new page in Contribute based on that template, Contribute always...
    3. DataBinding (Refreshing) a DataGrid within a Popup Window
      Hello, I'm trying to set up a modal (preferably) popup window to do asimple web service query. The popup window contains somecriteria fields, a...
    4. Datagrid is not refreshing after postback
      This problem shows up whenever I do any kind of update to the Access 2000 database - the update (delete, update, insert) works fine and the database...
    5. Refreshing DataGrid in page_load
      Hi, I want to refresh my DataGrid data on every postback. I have following code in Page_Load event, but after first page load, the DataGrid...
  3. #2

    Default Re: Refreshing datagrid

    Just call the .DataBind() method of the datagrid in the page you want to
    display the new data. Your datasource will have to be updated with the new
    info though. If your datasource is a dataset, this should be pretty easy
    and not involve going back to the database and requerying.

    "Ruby" <ruby@goldmart.co.id> wrote in message
    news:u2hl%23Cn2DHA.2952@TK2MSFTNGP09.phx.gbl...
    > Hi all...
    > I have an asp page with a datagrid, and a imagebutton to add a new row.
    > every time I click that new button, a new page appear and user can entry
    > data, save and close that page.
    > the problem is :
    > I want my datagrid reflecting the changes of my add new row, so every time
    I
    > save and close that add new record page,
    > automatically it add a new row in my datagrid
    >
    > thank
    >
    > ruby
    >
    >

    Michael Guest

  4. #3

    Default Re: Refreshing datagrid

    Why you don't use the same page to add the record directly to the datagrid?
    If this can be ok for you the ASP.NET WebMatrix has a good example for this
    in the new file template named "editable
    data grid" that come with the program...
    There also is another my post of today where I have also attached the
    file...

    Byez,
    Quasar


    "Ruby" <ruby@goldmart.co.id> ha scritto nel messaggio
    news:u2hl#Cn2DHA.2952@TK2MSFTNGP09.phx.gbl...
    > Hi all...
    > I have an asp page with a datagrid, and a imagebutton to add a new row.
    > every time I click that new button, a new page appear and user can entry
    > data, save and close that page.
    > the problem is :
    > I want my datagrid reflecting the changes of my add new row, so every time
    I
    > save and close that add new record page,
    > automatically it add a new row in my datagrid
    >
    > thank
    >
    > ruby
    >
    >

    QUASAR Guest

  5. #4

    Default Re: Refreshing datagrid

    Thank for advice, I also figured out that method, but the problem is, if
    I want to see records that i've entered at the same time i must open
    another browser to search for a spesific record

    Thank
    Ruby


    *** Sent via Developersdex [url]http://www.developersdex.com[/url] ***
    Don't just participate in USENET...get rewarded for it!
    Ruby Yanto Guest

  6. #5

    Default Re: Refreshing datagrid

    In What event should I put databind() method, since I don't know exactly
    what event will trigger when I close that add new record page

    thank

    Ruby



    *** Sent via Developersdex [url]http://www.developersdex.com[/url] ***
    Don't just participate in USENET...get rewarded for it!
    Ruby Yanto Guest

  7. #6

    Default refreshing datagrid

    Hi!
    I datagrid (dataset) that I fill from webservice. When I add new row
    to dataset, it`s ID it is writter on SQL server ok, but in datagrid
    it gets last id in datagrid +1, untill I take edit and datagrid
    refreshes from server and gets proper ID. For example, if I add new
    record that has id 2 on server and delite it (now next row has to have
    id 3), and again add new record in datagrid it shows id=2, but on
    server is id=3 (correct).
    So, I am asking you how to refresh my datagrid after adding new record
    in the sime step.

    my code html and aspx.cs is bellow.

    Thank you,
    Davorka

    <body>
    <form id="Institucije" method="post" runat="server">
    <h3 style="COLOR: darkslateblue; FONT-FAMILY: 'Times New Roman'"
    align="center">Ažuriranje
    institucija</h3>
    <asp:table id="Table1" Runat="server" Width="569px" Height="51px"
    BorderColor="DarkSlateBlue" BorderWidth="1px" BorderStyle="Double"
    HorizontalAlign="Center">
    <asp:TableRow BorderColor="DarkSlateBlue" BorderStyle="None"
    ID="Labele" BackColor="#CCCCFF" Font-Bold="True">
    <asp:TableCell Width="120px" HorizontalAlign="Center"
    BorderColor="DarkSlateBlue">
    <asp:Label runat="server" ID="lblDodajNovi">Dodaj
    novi</asp:Label>
    </asp:TableCell>
    <asp:TableCell>
    <asp:Label runat="server" ID="lblNaziv">Naziv</asp:Label>
    </asp:TableCell>
    <asp:TableCell>
    <asp:Label runat="server" ID="lblAdresa">Adresa</asp:Label>
    </asp:TableCell>
    </asp:TableRow>
    <asp:TableRow ID="NapraviNoviRed" BackColor="DarkSlateBlue">
    <asp:TableCell ColumnSpan="3">
    <asp:Button runat="server" Width="80px" ID="Create"
    Text="Kreiraj" OnClick="Create_Click"></asp:Button>
    </asp:TableCell>
    </asp:TableRow>
    <asp:TableRow BorderWidth="1px" BorderColor="DarkSlateBlue"
    BorderStyle="Solid" ID="DodajNoviRed" BackColor="DarkSlateBlue"
    Visible="False">
    <asp:TableCell>
    <asp:Button runat="server" Width="75px" ID="Dodaj" Height="25px"
    Text="OK" OnClick="Dodaj_Click"></asp:Button>
    <asp:Button runat="server" Width="75px" ID="Odustani"
    Height="25px" Text="Odustani" OnClick="Odustani_Click"></asp:Button>
    </asp:TableCell>
    <asp:TableCell VerticalAlign="Top" TabIndex="1">
    <asp:TextBox runat="server" Width="250px"
    ID="txNaziv"></asp:TextBox>
    <asp:RequiredFieldValidator runat="server" Display="Dynamic"
    ControlToValidate="txNaziv" ID="ProveriNaziv"> <br> *Naziv je
    obavezan!
    </asp:RequiredFieldValidator>
    </asp:TableCell>
    <asp:TableCell VerticalAlign="Top" TabIndex="2">
    <asp:TextBox runat="server" Width="250px"
    ID="txAdresa"></asp:TextBox>
    </asp:TableCell>
    </asp:TableRow>
    </asp:table><br>
    <asp:datagrid id=DataGrid1 runat="server" Width="568px"
    DataSource="<%# dsDepartmani %>" DataKeyField="ID institucije"
    DataMember="Institucije" AutoGenerateColumns="False"
    HorizontalAlign="Center" PageSize="15" BorderColor="DarkSlateBlue">
    <ItemStyle VerticalAlign="Middle"></ItemStyle>
    <HeaderStyle Font-Bold="True" HorizontalAlign="Center"
    VerticalAlign="Middle" BackColor="#CCCCFF"></HeaderStyle>
    <Columns>
    <asp:EditCommandColumn ButtonType="LinkButton"
    UpdateText="Update" CancelText="Cancel" EditText="Edit">
    <HeaderStyle Width="100pt"></HeaderStyle>
    </asp:EditCommandColumn>
    <asp:ButtonColumn Text="Delete" CommandName="Delete">
    <HeaderStyle Width="100pt"></HeaderStyle>
    </asp:ButtonColumn>
    <asp:TemplateColumn HeaderText="ID institucije">
    <HeaderStyle Width="250pt"></HeaderStyle>
    <ItemStyle HorizontalAlign="Center"></ItemStyle>
    <ItemTemplate>
    <asp:Label id=Label1 runat="server" Text='<%#
    DataBinder.Eval(Container, "DataItem.ID institucije") %>'>
    </asp:Label>
    </ItemTemplate>
    <EditItemTemplate>
    <asp:Label id=Label2 runat="server" Width="92px" Text='<%#
    DataBinder.Eval(Container, "DataItem.ID institucije") %>'>
    </asp:Label>
    </EditItemTemplate>
    </asp:TemplateColumn>
    <asp:TemplateColumn HeaderText="Naziv">
    <HeaderStyle Width="650pt"></HeaderStyle>
    <ItemStyle HorizontalAlign="Left"></ItemStyle>
    <ItemTemplate>
    <asp:Label runat="server" Text='<%# DataBinder.Eval(Container,
    "DataItem.Naziv") %>'>
    </asp:Label>
    </ItemTemplate>
    <EditItemTemplate>
    <asp:TextBox runat="server" Text='<%#
    DataBinder.Eval(Container, "DataItem.Naziv") %>'>
    </asp:TextBox>
    </EditItemTemplate>
    </asp:TemplateColumn>
    <asp:TemplateColumn HeaderText="Adresa">
    <HeaderStyle Width="650pt"></HeaderStyle>
    <ItemStyle HorizontalAlign="Left"></ItemStyle>
    <ItemTemplate>
    <asp:Label runat="server" Text='<%# DataBinder.Eval(Container,
    "DataItem.Adresa") %>'>
    </asp:Label>
    </ItemTemplate>
    <EditItemTemplate>
    <asp:TextBox runat="server" Text='<%#
    DataBinder.Eval(Container, "DataItem.Adresa") %>'>
    </asp:TextBox>
    </EditItemTemplate>
    </asp:TemplateColumn>
    </Columns>
    </asp:datagrid><br>
    <br>
    </form>
    <script runat="server">
    protected void Create_Click(object sender, EventArgs e)
    {
    ShowAddNewControls(true);
    DataGrid1.EditItemIndex=-1;
    DataGrid1.DataBind();
    }

    protected void ShowAddNewControls(bool ShowControls)
    {txNaziv.Text="";
    txAdresa.Text="";
    DodajNoviRed.Visible=ShowControls;
    NapraviNoviRed.Visible=!ShowControls;
    txNaziv.Visible=ShowControls;
    txAdresa.Visible=ShowControls;

    }

    private void Dodaj_Click(object sender, EventArgs e)
    {
    if(Page.IsValid)
    {
    WebRaspored2.localhost.DsDepartmani.InstitucijeRow instRow=
    dsDepartmani.Institucije.NewInstitucijeRow();

    instRow.Naziv =txNaziv.Text;
    instRow.Adresa =txAdresa.Text;

    dsDepartmani.Institucije.AddInstitucijeRow(instRow );
    WebRaspored2.localhost.RasporedService s= new
    WebRaspored2.localhost.RasporedService();
    s.WebSnimi(dsDepartmani);
    dsDepartmani.AcceptChanges();
    DataGrid1.DataBind();
    ShowAddNewControls(false);
    }
    }

    protected void Odustani_Click(object sender, EventArgs e)
    {
    ShowAddNewControls(false);
    }
    </script>
    </body>
    </HTML>


    using WebRaspored2.localhost;


    namespace WebRaspored2
    {
    /// <summary>
    /// Summary description for Institucije.
    /// </summary>
    public class Institucije : System.Web.UI.Page
    {
    protected System.Web.UI.WebControls.DataGrid DataGrid1;
    protected System.Web.UI.WebControls.TextBox tbNaziv;
    protected System.Web.UI.WebControls.TextBox tbAdresa;
    protected System.Web.UI.WebControls.Button btnDodaj;
    protected System.Web.UI.WebControls.Table Table1;
    protected System.Web.UI.WebControls.RequiredFieldValidator
    RequiredFieldValidator1;
    protected DsDepartmani dsDepartmani;

    private void Page_Load(object sender, System.EventArgs e)
    {
    // Put user code to initialize the page here
    localhost.RasporedService s= new localhost.RasporedService();
    dsDepartmani=s.WebPopuni("Institucije");
    DataGrid1.DataSource=dsDepartmani;
    DataGrid1.DataMember="Institucije";

    if(!IsPostBack)
    DataGrid1.DataBind();

    }

    *Web Form Designer generated code*


    private void DataGrid1_CancelCommand(object source,
    System.Web.UI.WebControls.DataGridCommandEventArgs e)
    {
    DataGrid1.EditItemIndex = -1;
    DataGrid1.DataBind();


    }

    private void DataGrid1_EditCommand(object source,
    System.Web.UI.WebControls.DataGridCommandEventArgs e)
    {
    //ShowAddNewControls(false);
    DataGrid1.EditItemIndex = e.Item.ItemIndex;
    DataGrid1.DataBind();
    }

    private void DataGrid1_UpdateCommand(object source,
    System.Web.UI.WebControls.DataGridCommandEventArgs e)
    { //ShowAddNewControls(false);
    localhost.RasporedService s= new localhost.RasporedService();

    string naz, adr;
    string key = DataGrid1.DataKeys[e.Item.ItemIndex].ToString();
    TextBox tb;
    tb=(TextBox)(e.Item.Cells[3].Controls[1]);
    naz = tb.Text;
    tb=(TextBox)(e.Item.Cells[4].Controls[1]);
    adr=tb.Text;
    DsDepartmani.InstitucijeRow rd;
    rd=dsDepartmani.Institucije.FindByID_institucije(i nt.Parse(key));
    if (rd!=null)
    {
    rd.Naziv=naz;
    rd.Adresa=adr;

    // Calls a SQL statement to update the database from the dataset
    //sqlDataAdapter1.Update(dsCategories1);
    //localhost.RasporedService s= new localhost.RasporedService();

    s.WebSnimi(dsDepartmani);
    dsDepartmani.AcceptChanges();
    }


    // Takes the DataGrid row out of editing mode
    DataGrid1.EditItemIndex = -1;

    // Refreshes the grid
    DataGrid1.DataBind();
    }

    private void DataGrid1_DeleteCommand(object source,
    System.Web.UI.WebControls.DataGridCommandEventArgs e)
    {
    try
    {
    int rowToDelete = e.Item.ItemIndex;
    // Add code to delete row from data source.
    dsDepartmani.Institucije[rowToDelete].Delete();
    localhost.RasporedService s= new localhost.RasporedService();
    s.WebSnimi(dsDepartmani);
    dsDepartmani.AcceptChanges();
    DataGrid1.DataBind();
    }
    catch (InvalidCastException ex)
    {


    }

    }


    }
    dada Guest

  8. #7

    Default Re: refreshing datagrid

    I still haven`t solved the problem, somebody help please.
    Dada
    dada Guest

Posting Permissions

  • You may not post new threads
  • You may post replies
  • You may not post attachments
  • You may not edit your posts

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139