Scott said:
Yes - it is reset. If you have the same data in the drop down -
couldn't you just let the data be restored from viewstate and not
rebind? Perhaps I am not understanding your question, apologies.
hi scott!
if i display the data then an index is selected. but if i go to edit
mode, this selected index is set to 0 after i get the data from the drop
downlist again (requesting the data again from database.
heres some sample code:
page.aspx
<asp:datagrid id="dgSoftware" style="Z-INDEX: 102; LEFT: 23px; POSITION:
absolute; TOP: 68px"
runat="server" Height="235px" Width="856px"
AutoGenerateColumns="False" DataKeyField="sw_ref" GridLines="None"
CellPadding="3" BackColor="White"
BorderWidth="2px" CellSpacing="1" BorderStyle="Ridge"
BorderColor="White">
<SelectedItemStyle Font-Bold="True" ForeColor="White"
BackColor="#9471DE"></SelectedItemStyle>
<ItemStyle ForeColor="Black" BackColor="#DEDFDE"></ItemStyle>
<HeaderStyle Font-Bold="True" ForeColor="#E7E7FF"
BackColor="#4A3C8C"></HeaderStyle>
<FooterStyle ForeColor="Black" BackColor="#C6C3C6"></FooterStyle>
<Columns>
<asp:BoundColumn DataField="sw_bez_str"
HeaderText="Bezeichnung"></asp:BoundColumn>
<asp:BoundColumn DataField="sw_herst_str"
HeaderText="Hersteller"></asp:BoundColumn>
<asp:BoundColumn DataField="sw_filesys_str"
HeaderText="Dateisystem"></asp:BoundColumn>
<asp:TemplateColumn HeaderText="Softwareart">
<ItemTemplate>
<%# getHtswtyp(DataBinder.Eval(Container.DataItem,
"htswtyp_ref")) %>
</ItemTemplate>
<EditItemTemplate>
<asp

ropDownList ID="DropDownSwref" Runat="server"
DataTextField="htswtyp_name_str" DataValueField="htswtyp_ref" />
</EditItemTemplate>
</asp:TemplateColumn>
<asp:BoundColumn DataField="sw_bem_str"
HeaderText="Bemerkung"></asp:BoundColumn>
<asp:TemplateColumn HeaderText="zugehörige Hardware">
<ItemTemplate>
<%# getHwref(DataBinder.Eval(Container.DataItem,
"hw_ref")) %>
</ItemTemplate>
<EditItemTemplate>
<asp

ropDownList ID="DropDownHwref" Runat="server"
DataTextField="id" DataValueField="hwId"/>
</EditItemTemplate>
</asp:TemplateColumn>
<asp:EditCommandColumn ButtonType="LinkButton"
UpdateText="Aktualisieren" CancelText="Abbrechen"
EditText="Bearbeiten"></asp:EditCommandColumn>
<asp:ButtonColumn Text="Löschen"
CommandName="Delete"></asp:ButtonColumn>
</Columns>
<PagerStyle HorizontalAlign="Right" ForeColor="Black"
Position="TopAndBottom" BackColor="#C6C3C6"></PagerStyle>
</asp:datagrid>
and heres the page.aspx.cs:
....
private void Page_Load(object sender, System.EventArgs e)
{
if (!IsPostBack)
{
showDataSoftware();
showDataHardware();
}
}
....
private void dgSoftware_EditCommand(object source,
System.Web.UI.WebControls.DataGridCommandEventArgs e)
{
this.dgSoftware.EditItemIndex = e.Item.ItemIndex;
showDataSoftware();
}
....
protected void dgSoftware_ItemDataBound ( System.Object sender,
System.Web.UI.WebControls.DataGridItemEventArgs e )
{
if( e.Item.ItemType == ListItemType.EditItem)
{
//erzeuge ddl fuer softwareart
DropDownList list2 =
(DropDownList)e.Item.FindControl("DropDownSwref");
string query = "SELECT htswtyp_ref, htswtyp_name_str FROM htswtyp";
this.sqlConn.Open();
SqlCommand cmd = new SqlCommand(query, this.sqlConn);
list2.DataSource = cmd.ExecuteReader();
list2.DataBind();
this.sqlConn.Close();
}
}
....
private void showDataSoftware()
{
string strWherebuilder = "";
for (int i =0; i < this.alHwId.Count; i++)
{
if (this.alHwId.Count == 1 || i == (this.alHwId.Count-1) )
strWherebuilder += this.alHwId
.ToString();
else strWherebuilder += this.alHwId.ToString() + " OR hw_ref
= ";
}
string query = "SELECT * FROM sw WHERE hw_ref = " + strWherebuilder;
//DEBUG
this.tbDebug.Text += "QUERY: " + query;
this.sqlConn = new SqlConnection(this.strDbConn);
this.sqlAdapter = new SqlDataAdapter(query, this.sqlConn);
this.sqlConn.Open();
this.dsDaten = new DataSet();
this.sqlAdapter.Fill(this.dsDaten, "sw" );
this.createList(query);
//neue zeile einfuegen
DataRow BlankRow = this.dsDaten.Tables["sw"].NewRow( );
BlankRow[1] = "Bitte Wert eingeben!";
this.dsDaten.Tables[ "sw" ].Rows.InsertAt( BlankRow, 0 );
//daten binden
this.dgSoftware.DataSource = this.dsDaten;
this.dgSoftware.DataBind();
this.sqlConn.Close();
}
i think the problem is to re-request the data from database.
hope you may help me.
regards
wolfgang