Tolong pilih kategori sesuai, jenis posting (diskusi atau bukan) dan sertakan tag/topik yang sesuai seperti komputer, java, php, mysql, dll. Promosi atau posting tidak pada tempatnya akan kami hapus!
- Bagi Anda yang ingin mendaftar, baca link berikut:
http://diskusiweb.com/discussion/50491/how-to-registrasi-diskusiweb-com-baca-ini-terlebih-dahulu
- Cara menyisipkan kode program supaya tampil rapi dan terformat dengan baik di diskusiweb.com: http://www.diskusiweb.com/discussion/50415/cara-menyisipkan-kode-program-di-diskusiweb-com
- Cara posting gambar/image di post Anda: http://www.diskusiweb.com/discussion/47345/cara-menyisipkan-menyertakan-image-pada-posting/p1

Update Form

dede,

saya ingin bertanya mengenai update.

selama ini untuk proses update adalah dengan update di datagrid yang bersangkutan.

yang saya ingin tanyakan bagaimana jika untuk update saya tidak ingin di datagrid
tapi di formpage yang lain

terima kasih

salam,

Comments

  • edited January 2011
    tansfer data antara page bisa dengan querystring, session, context.items, application.

    contohnya seperti ini
    di page grid.aspx, pada event edit di berikan code:<div class='geshi_syntax'><table><tr><td><div class='code'><pre class="vb"> <span class="kw2">Sub</span> MyGrid_EditCommand(sender <span class="kw4">As</span> <span class="kw1">Object</span>, e <span class="kw4">As</span> DataGridCommandEventArgs)
    <span class="kw4">Dim</span> dataID <span class="kw4">As</span> <span class="kw1">String</span> = e.Item.Cells(0).Text
    Context.Items.Add(<span class="st0">"DataGridID"</span>, dataID)
    Server.Transfer(<span class="st0">"Edit.aspx"</span>,<span class="kw5">True</span>)
    <span class="kw3">End</span> <span class="kw2">Sub</span></pre></div></td></tr></table></div>
    dan di page edit.aspx, meng-akses-nya seperti ini:<div class='geshi_syntax'><table><tr><td><div class='code'><pre class="vb"><span class="kw2">Sub</span> Page_Load(sender <span class="kw4">As</span> <span class="kw1">Object</span>, e <span class="kw4">As</span> EventArgs)
    <span class="kw4">Dim</span> dataID <span class="kw4">As</span> <span class="kw1">String</span> = Context.Items(<span class="st0">"DataGridID"</span>)
    <span class="kw3">If</span> dataID <span class="kw3">Is</span> <span class="kw5">Nothing</span> <span class="kw3">Then</span>
    Response.Redirect(<span class="st0">"Grid.aspx"</span>)
    <span class="kw3">End</span> <span class="kw3">If</span>
    Response.Write(<span class="st0">"Data ID: <b>"</span> & dataID & <span class="st0">"</b><br />"</span>)
    <span class="kw3">End</span> <span class="kw2">Sub</span></pre></div></td></tr></table></div>
  • dede,
    saya mau tanya lebih detail.

    misalkan saya mempunyai grid.aspx disana terdapat datagrid dengan field kode dan nama kemudian ada button edit

    biasanya ketika saya menekan button update maka datagrid di grid.aspx akan menjadi enable.

    sekarang saya ingin mencoba bagaimana jika saya menekan edit informasi yang saya edit berada di form.aspx

    di form.aspx sudah disediakan textbox untuk menampung kode dan nama.

    terima kasih atas masukannya,

    salam,
  • edited January 2011
    anda bisa lihat modifikasi grid di bawah:<div class='geshi_syntax'><table><tr><td><div class='code'><pre class="vb"><asp:datagrid id=<span class="st0">"MyGrid"</span> runat=<span class="st0">"server"</span> BorderColor=<span class="st0">"LightGray"</span> BorderStyle=<span class="st0">"Solid"</span> BorderWidth=<span class="st0">"1px"</span> BackColor=<span class="st0">"White"</span>
    CellPadding=<span class="st0">"3"</span> GridLines=<span class="st0">"Vertical"</span> ForeColor=<span class="st0">"Black"</span> Font-Names=<span class="st0">"Tahoma"</span> Font-Size=<span class="st0">"X-Small"</span> AllowPaging=<span class="st0">"True"</span> AutoGenerateColumns=<span class="st0">"False"</span> OnEditCommand=<span class="st0">"MyGrid_EditCommand"</span> OnPageIndexChanged=<span class="st0">"MyGrid_PageIndexChanged"</span>>
    <FooterStyle backcolor=<span class="st0">"#CCCCCC"</span>></FooterStyle>
    <SelectedItemStyle font-bold=<span class="st0">"True"</span> forecolor=<span class="st0">"White"</span> backcolor=<span class="st0">"#000099"</span>></SelectedItemStyle>
    <AlternatingItemStyle backcolor=<span class="st0">"Gainsboro"</span>></AlternatingItemStyle>
    <HeaderStyle font-bold=<span class="st0">"True"</span> forecolor=<span class="st0">"White"</span> backcolor=<span class="st0">"Black"</span>></HeaderStyle>
    <Columns>
    <asp:BoundColumn Visible=<span class="st0">"False"</span> DataField=<span class="st0">"CustomerID"</span> ReadOnly=<span class="st0">"True"</span> HeaderText=<span class="st0">"ID"</span>></asp:BoundColumn>
    <asp:BoundColumn DataField=<span class="st0">"CompanyName"</span> ReadOnly=<span class="st0">"True"</span> HeaderText=<span class="st0">"Company"</span>></asp:BoundColumn>
    <asp:BoundColumn DataField=<span class="st0">"City"</span> ReadOnly=<span class="st0">"True"</span> HeaderText=<span class="st0">"City"</span>></asp:BoundColumn>
    <asp:BoundColumn DataField=<span class="st0">"Country"</span> ReadOnly=<span class="st0">"True"</span> HeaderText=<span class="st0">"Country"</span>></asp:BoundColumn>
    <asp:ButtonColumn Text=<span class="st0">"Edit"</span> ButtonType=<span class="st0">"PushButton"</span> CommandName=<span class="st0">"Edit"</span>></asp:ButtonColumn>
    </Columns>
    <PagerStyle horizontalalign=<span class="st0">"Right"</span> forecolor=<span class="st0">"Black"</span> backcolor=<span class="st0">"LightGray"</span> mode=<span class="st0">"NumericPages"</span>></PagerStyle>
    </asp:datagrid></pre></div></td></tr></table></div>

    ada kemungkinan anda membuat di grid seperti ini:<div class='geshi_syntax'><table><tr><td><div class='code'><pre class="vb"><asp:EditCommandColumn ButtonType=<span class="st0">"LinkButton"</span> UpdateText=<span class="st0">"Update"</span> CancelText=<span class="st0">"Cancel"</span> EditText=<span class="st0">"Edit"</span>></asp:EditCommandColumn></pre></div></td></tr></table></div>
    maka setiap meng-click edit akan menjadi enable mode.
  • de, kalo misalkan update ke form page gimana? saya masih belom berhasil nih bisa kasi sample nga yah

    terima kasih,
  • edited January 2011

    begin GigiGrid.aspx
    <div class='geshi_syntax'><table><tr><td><div class='code'><pre class="vb"><%@ Page Language=<span class="st0">"VB"</span> %>
    <%@ import Namespace=<span class="st0">"System"</span> %>
    <%@ import Namespace=<span class="st0">"System.Data"</span> %>
    <%@ import Namespace=<span class="st0">"System.Data.OleDb"</span> %>
    <script runat=<span class="st0">"server"</span>>
    <span class="kw2">Sub</span> BindGrid()
    <span class="kw4">Dim</span> connectionString <span class="kw4">As</span> <span class="kw1">String</span> = <span class="st0">"Provider=Microsoft.Jet.OLEDB.4.0; Data Source=C:\Inetpub\wwwroot\NWIND.MDB; User Id=admin; Password=;"</span>
    <span class="kw4">Dim</span> sql <span class="kw4">As</span> <span class="kw1">String</span> = <span class="st0">"SELECT CustomerID,CompanyName,City,Country FROM Customers"</span>
    <span class="kw4">Dim</span> da <span class="kw4">As</span> OleDbDataAdapter
    <span class="kw4">Dim</span> ds <span class="kw4">As</span> <span class="kw2">New</span> DataSet
     
    Try
    da = <span class="kw2">New</span> OleDbDataAdapter(sql, connectionString)
    da.Fill(ds)
    MyGrid.DataSource = ds
    MyGrid.DataBind()
    Catch ex <span class="kw4">As</span> Exception
    Response.Write(<span class="st0">"<b>"</span> & ex.Message & <span class="st0">"</b><br />"</span>)
    Finally
    da.Dispose()
    da = <span class="kw5">Nothing</span>
    <span class="kw3">End</span> Try
     
    <span class="kw3">End</span> <span class="kw2">Sub</span>
     
    <span class="kw2">Sub</span> Page_Load(sender <span class="kw4">As</span> <span class="kw1">Object</span>, e <span class="kw4">As</span> EventArgs)
    <span class="kw3">If</span> <span class="kw3">Not</span> IsPostBack <span class="kw3">Then</span>
    BindGrid()
    <span class="kw3">End</span> <span class="kw3">If</span>
    <span class="kw3">End</span> <span class="kw2">Sub</span>
     
    <span class="kw2">Sub</span> MyGrid_EditCommand(sender <span class="kw4">As</span> <span class="kw1">Object</span>, e <span class="kw4">As</span> DataGridCommandEventArgs)
    <span class="kw4">Dim</span> dataID <span class="kw4">As</span> <span class="kw1">String</span> = e.Item.Cells(0).Text
    Context.Items.Add(<span class="st0">"DataGridID"</span>, dataID)
    Server.Transfer(<span class="st0">"GigiEdit.aspx"</span>,<span class="kw5">True</span>)
    <span class="kw3">End</span> <span class="kw2">Sub</span>
     
    <span class="kw2">Sub</span> MyGrid_PageIndexChanged(sender <span class="kw4">As</span> <span class="kw1">Object</span>, e <span class="kw4">As</span> DataGridPageChangedEventArgs)
    MyGrid.CurrentPageIndex = e.NewPageIndex
    BindGrid()
    <span class="kw3">End</span> <span class="kw2">Sub</span>
     
    </script>
     
    <html>
    <head></head>
    <body>
    <form runat=<span class="st0">"server"</span>>
    <asp:datagrid id=<span class="st0">"MyGrid"</span> runat=<span class="st0">"server"</span>
    BorderColor=<span class="st0">"LightGray"</span> BorderStyle=<span class="st0">"Solid"</span> BorderWidth=<span class="st0">"1px"</span> BackColor=<span class="st0">"White"</span>
    CellPadding=<span class="st0">"3"</span> GridLines=<span class="st0">"Vertical"</span> ForeColor=<span class="st0">"Black"</span> Font-Names=<span class="st0">"Tahoma"</span> Font-Size=<span class="st0">"X-Small"</span>
    AllowPaging=<span class="st0">"True"</span> AutoGenerateColumns=<span class="st0">"False"</span> OnEditCommand=<span class="st0">"MyGrid_EditCommand"</span> OnPageIndexChanged=<span class="st0">"MyGrid_PageIndexChanged"</span>>
    <FooterStyle backcolor=<span class="st0">"#CCCCCC"</span>></FooterStyle>
    <SelectedItemStyle font-bold=<span class="st0">"True"</span> forecolor=<span class="st0">"White"</span> backcolor=<span class="st0">"#000099"</span>></SelectedItemStyle>
    <AlternatingItemStyle backcolor=<span class="st0">"Gainsboro"</span>></AlternatingItemStyle>
    <HeaderStyle font-bold=<span class="st0">"True"</span> forecolor=<span class="st0">"White"</span> backcolor=<span class="st0">"Black"</span>></HeaderStyle>
    <Columns>
    <asp:BoundColumn Visible=<span class="st0">"False"</span> DataField=<span class="st0">"CustomerID"</span> ReadOnly=<span class="st0">"True"</span> HeaderText=<span class="st0">"ID"</span> ></asp:BoundColumn>
    <asp:BoundColumn DataField=<span class="st0">"CompanyName"</span>ReadOnly=<span class="st0">"True"</span> HeaderText=<span class="st0">"Company"</span> ></asp:BoundColumn>
    <asp:BoundColumn DataField=<span class="st0">"City"</span> ReadOnly=<span class="st0">"True"</span> HeaderText=<span class="st0">"City"</span> ></asp:BoundColumn>
    <asp:BoundColumn DataField=<span class="st0">"Country"</span> ReadOnly=<span class="st0">"True"</span> HeaderText=<span class="st0">"Country"</span> ></asp:BoundColumn>
    <asp:ButtonColumn Text=<span class="st0">"Edit"</span> ButtonType=<span class="st0">"PushButton"</span> CommandName=<span class="st0">"Edit"</span> ></asp:BoundColumn>
    </Columns>
    <PagerStyle horizontalalign=<span class="st0">"Right"</span> forecolor=<span class="st0">"Black"</span> backcolor=<span class="st0">"LightGray"</span> mode=<span class="st0">"NumericPages"</span>></PagerStyle>
    </asp:datagrid>
    </form>
    </body>
    </html></pre></div></td></tr></table></div>
    end GigiGrid.aspx

    begin GigiEdit.aspx
    <div class='geshi_syntax'><table><tr><td><div class='code'><pre class="vb"><%@ Page Language=<span class="st0">"VB"</span> %>
    <script runat=<span class="st0">"server"</span>>
     
    <span class="kw2">Sub</span> Page_Load(sender <span class="kw4">As</span> <span class="kw1">Object</span>, e <span class="kw4">As</span> EventArgs)
     
    <span class="kw3">If</span> <span class="kw3">Not</span> IsPostBack <span class="kw3">Then</span>
     
    <span class="kw4">Dim</span> dataID <span class="kw4">As</span> <span class="kw1">String</span> = Context.Items(<span class="st0">"DataGridID"</span>)
     
    <span class="kw3">If</span> dataID <span class="kw3">Is</span> <span class="kw5">Nothing</span> <span class="kw3">Then</span>
    Response.Redirect(<span class="st0">"GigiGrid.aspx"</span>, <span class="kw5">True</span>)
    <span class="kw3">End</span> <span class="kw3">If</span>
     
    lblID.Text = <span class="st0">"Data ID: <b>"</span> & dataID & <span class="st0">"</b><br />"</span>
    <span class="co1">' anda bisa query by ID atau anda kirim melalui context.items
    </span> <span class="co1">' untuk binding ke textbox di page edit anda.
    </span>
    <span class="kw3">End</span> <span class="kw3">If</span>
     
    <span class="kw3">End</span> <span class="kw2">Sub</span>
     
    </script>
    <html>
    <head>
    <title>Edit Page</title>
    </head>
    <body>
    <form runat=<span class="st0">"server"</span>>
    <asp:Label id=<span class="st0">"lblID"</span> runat=<span class="st0">"server"</span>></asp:Label>
    </form>
    </body>
    </html></pre></div></td></tr></table></div>
    end GigiEdit.aspx
  • hi Dede,
    bisa minta contoh halaman GigiEdit.aspx nya?
    thanks


    Marsha Putri
  • GigiEdit.aspx -nya anda perhatikan berada di antara
    begin GigiEdit.aspx
    dan
    end GigiEdit.aspx

    copy dan paste di notepad/editor lalu save sebagai GigiEdit.aspx
Sign In or Register to comment.