w3hello.com logo
Home PHP C# C++ Android Java Javascript Python IOS SQL HTML videos Categories
asp.net DataList select DropDownList value

In your bind method you are calling an object e that doesn't exist. If the dropdownlist isn't inside a bound element, you can just reference the front code directly, e.g.

drpdKategoria.DataSource = ds;
drpdKategoria.DataValueField = "id";  // Value of bided list in your
dropdown in your case it will be CATEGORY_ID
drpdKategoria.DataTextField = "emertimi"; // this will show Category name
in your dropdown
drpdKategoria.DataBind();

without finding the control as long as it is runat="server"

UPDATE

Okay, so you need to add an OnItemCreated event in your datalist

OnItemCreated="datalist2_OnItemCreated"

Then in that method you need this

protected void datalist2_OnItemCreated(object sender,
DataListItemEventArgs e)
{
    if (e.Item.ItemType == ListItemType.Footer)
    {
        DropDownList drpdKategoria = e.Item.FindControl("drpdKategoria") as
DropDownList;
        SqlConnection con = new SqlConnection(connection)
        string Qry = "select * from kategoria";
        SqlDataAdapter da = new SqlDataAdapter(Qry, con);
        DataSet ds = new DataSet();
        con.Open();
        da.Fill(ds);
        drpdKategoria.DataSource = ds;
        drpdKategoria.DataValueField = "id";
        drpdKategoria.DataTextField = "emertimi";
        drpdKategoria.DataBind();
        con.Close();
        con.Dispose();
        ds.Dispose();
        da.Dispose(); 
    }
}

That will work for if you only have the footer, if you add an itemtemplate then you just need to get rid of the check for the footer and on each item creation grab that dropdownlist for that item





© Copyright 2018 w3hello.com Publishing Limited. All rights reserved.