0

I have make a gridview with object data source. I make a class for the Object Data Source and make the gridview in aspx page.

It was run perfectly, but i want to make, when i update the table, there is two coloumn that will turn into dropdownlist, not free text.

I dont know how to make that, can you make/give me some example. This is my Object Data Source Class:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;

namespace quittance.Kelas
{
    public class dalamkota_rincian_8:daftarproperti
    {
        public static List<daftarproperti> AmbilJadwal(string nomorSt)
        {
            List<daftarproperti> Listjadwal = new List<daftarproperti>();
            string CS = ConfigurationManager.ConnectionStrings["nikita_app"].ConnectionString;

            using (SqlConnection con = new SqlConnection(CS))
            {
                SqlCommand cmd = new SqlCommand("xp_generatejadwal_dalamkota8", con);
                cmd.CommandType = CommandType.StoredProcedure;
                SqlParameter paramnoSt = new SqlParameter("@nomorSt", nomorSt);
                cmd.Parameters.Add(paramnoSt);
                con.Open();
                SqlDataReader rdr = cmd.ExecuteReader();
                while (rdr.Read())
                {
                    daftarproperti jadwal = new daftarproperti();
                    jadwal.tugasID = (int)rdr["tugasID"];
                    jadwal.nama = rdr["nama"].ToString();
                    jadwal.nip = rdr["nip"].ToString();
                    jadwal.gol = rdr["gol"].ToString();
                    jadwal.tgl_mulai = rdr["tgl_mulai"].ToString();
                    jadwal.tgl_selesai = rdr["tgl_selesai"].ToString();
                    jadwal.jumlahhari1 = rdr["jumlahhari1"] as int? ?? default(int);
                    Listjadwal.Add(jadwal);
                }
            }

            return Listjadwal;
        }
    }
}

The Object Data Source and the Gridview has been connected.

<asp:ObjectDataSource ID="ds_dalamkota8_jadwal" runat="server" DeleteMethod="DeleteJadwal" InsertMethod="InsertJadwal" SelectMethod="AmbilJadwal" TypeName="quittance.Kelas.dalamkota_rincian_8" UpdateMethod="UpdateJadwal">
                        <DeleteParameters>
                            <asp:Parameter Name="tugasID" Type="Int32" />
                        </DeleteParameters>
                        <InsertParameters>
                            <asp:Parameter Name="nip" Type="String" />
                            <asp:Parameter Name="gol" Type="String" />
                            <asp:Parameter Name="kdlokasi" Type="Int32" />
                            <asp:Parameter Name="tgl_mulai" Type="String" />
                            <asp:Parameter Name="tgl_selesai" Type="String" />
                        </InsertParameters>
                        <SelectParameters>
                            <asp:SessionParameter Name="nomorSt" SessionField="nomorst" Type="String" />
                        </SelectParameters>
                        <UpdateParameters>
                            <asp:Parameter Name="tugasID" Type="Int32" />
                            <asp:Parameter Name="nip" Type="String" />
                            <asp:Parameter Name="gol" Type="String" />
                            <asp:Parameter Name="kdlokasi" Type="Int32" />
                            <asp:Parameter Name="tgl_mulai" Type="String" />
                            <asp:Parameter Name="tgl_selesai" Type="String" />
                        </UpdateParameters>
                    </asp:ObjectDataSource>

I want to make the nip and gol coloumn turn into dropdownlist when i edit that. I dont know how to make it with object data source, should i make in Object Data Source class or in aspx.cs page with sqldatasource. Please give me an example/explanation.

arbutrus
  • 37
  • 10

1 Answers1

0

you can call the method one which provide data from the page load event then you a can bind data to drop down

protected void Page_Load(object sender, EventArgs e)
{
    if (!IsPostBack)
    {
        GridView1.DataSource =  AmbilJadwal(nomorSt);
        GridView1.DataBind();
    }
}

Help link is given below most likely it will solve your problem

Bind DropDownList in ItemTemplate of TemplateField in ASP.Net GridView

MMM
  • 3,132
  • 3
  • 20
  • 32
  • The gridview has connected with the object data source Midhun, it has already can retrieve data. The concern here is how to make a dropdownlist bind when i clicked edit. – arbutrus Jun 19 '16 at 06:13
  • add an event handler to the button edit click write code to bind dropdown in edit event handler@AndreasSyaloomKurniawan – MMM Jun 19 '16 at 06:20
  • Thank for your advice, can you see this example http://stackoverflow.com/questions/9029702/c-sharp-selectedvalue-of-dropdownlist-with-objectdatasource ; there is an answer there with dropdownlist is hardcoded on aspx page. Can you help how to achieved that if i want to make dropdownlist in my data access layer class. This is the question. It hard to me because my Gridview source come from Object Data Source, if i made it in SQL Data Source i know how to bind it :) – arbutrus Jun 19 '16 at 06:39