Than you Selim for your help, I have tried that but it doesn`t work.
I get an error
"System.NullReferenceException: Object reference not set to an
instance of an object."
I am sending you my code, if you be so cind to see what I am doing
wrong.
Thank you again,
Dada
***
using WebRaspored2.localhost;
namespace WebRaspored2
{
public class Departmani : System.Web.UI.Page
{
protected System.Web.UI.WebControls.Table Table1;
protected System.Web.UI.WebControls.DataGrid DataGrid1;
protected WebRaspored2.localhost.DsDepartmani dsDepartmani;
private void Page_Load(object sender, System.EventArgs e)
{
localhost.RasporedService s= new localhost.RasporedService();
dsDepartmani=s.WebPopuni("Departmani");
DataGrid1.DataSource=dsDepartmani;
DataGrid1.DataMember="Departmani";
if(!IsPostBack)
DataGrid1.DataBind();
}
private void DataGrid1_UpdateCommand(object source,
System.Web.UI.WebControls.DataGridCommandEventArgs e)
{
localhost.RasporedService s= new localhost.RasporedService();
string naz;
int Institucije;
string key = DataGrid1.DataKeys[e.Item.ItemIndex].ToString();
TextBox tb;
tb=(TextBox)(e.Item.Cells[3].Controls[1]);
naz = tb.Text;
DropDownList ddl;
ddl=(DropDownList)(e.Item.Cells[5].Controls[1]);
Institucije=Convert.ToInt32(ddl.SelectedItem.Value);
DsDepartmani.DepartmaniRow rd;
rd=dsDepartmani.Departmani.FindByID_departmana(int.Parse(key));
if (rd!=null)
{
rd.Naziv=naz;
rd.ID_institucije=Convert.ToInt32(Institucije);
s.WebSnimi(dsDepartmani);
dsDepartmani.AcceptChanges();
}
DataGrid1.EditItemIndex = -1;
DataGrid1.DataBind();
}
private void DataGrid1_ItemDataBound(object sender,
System.Web.UI.WebControls.DataGridItemEventArgs e)
{
DropDownList ddl=(DropDownList) e.Item.FindControl("DropDownList1");
ddl.SelectedIndex=ddl.Items.IndexOf(ddl.Items.FindByValue("ID
institucije"));
//if(e.Item.ItemType == ListItemType.EditItem)
// {
//DataRowView drv = (DataRowView) e.Item.DataItem;
//String IDinst = drv["ID institucije"].ToString();
//DropDownList ddl =(DropDownList)
e.Item.FindControl("DropDownList1");
//ddl.SelectedIndex = ddl.Items.IndexOf(ddl.Items.FindByText(IDinst));
//
// }
}
HTML:
<asp:TemplateColumn HeaderText="Institucija">
<HeaderStyle Width="350pt"></HeaderStyle>
<ItemTemplate>
<asp:Label id=Label1 runat="server" Text='<%#
DataBinder.Eval(Container, "DataItem.Institucije") %>'>
</asp:Label>
</ItemTemplate>
<EditItemTemplate>
<asp

ropDownList id=DropDownList1 runat="server" Width="239px"
DataMember="Institucije" DataSource="<%# dsDepartmani %>"
DataTextField="Naziv" DataValueField="ID institucije">
</asp

ropDownList>
</EditItemTemplate>
</asp:TemplateColumn>