Hallo Forum
Ich habe folgende Gridview in meiner Website:
und folgenden Code Behind:
Eigentlich klappt alles mit ausnahme des DropDown. es wird zwar der richtige wert eingestellt beim editieren, wenn ich aber den Datensatz aktualisiere speichert er immer eine -1 oder 0 ab, und dies willkürlich...
Weiss jemand einen Rat dazu
Gruss
Markus
Ich habe folgende Gridview in meiner Website:
HTML-Quellcode
- <asp:SqlDataSource ID="CustomersSource2" runat="server" ProviderName="System.Data.OleDb"
- SelectCommand = "select * from MITGLIEDER order by M_AUSTRITT asc, M_NACHNAME asc" />
- <asp:GridView ID="GridView2" CssStyle="Black12" runat="server" SelectedRowStyle-BackColor="#FFFFCC" DataSourceID="CustomersSource2" DataKeyNames="M_ID" AutoGenerateColumns="False" HorizontalAlign="Center" BorderStyle="Solid" BorderWidth="1px" HeaderStyle-CssClass="table12">
- <Columns>
- <asp:BoundField DataField="M_ID" HeaderText="ID" SortExpression="M_ID" ItemStyle-Width="75" ControlStyle-Width="95%" ReadOnly="True" visible="false" />
- <asp:BoundField DataField="M_NACHNAME" HeaderText="Nachanme" SortExpression="M_NACHNAME" ItemStyle-Width="250" ControlStyle-Width="95%" ReadOnly="True" />
- <asp:BoundField DataField="M_VORNAME" HeaderText="Vorname" SortExpression="M_VORNAME" ItemStyle-Width="250" ControlStyle-Width="95%" ReadOnly="True" />
- <asp:BoundField DataField="M_MAIL" HeaderText="E-Mail" SortExpression="M_MAIL" ItemStyle-Width="250" ControlStyle-Width="95%" ReadOnly="True"/>
- <asp:CheckBoxField DataField="M_NL" HeaderText="Newsletter" SortExpression="M_NL" ItemStyle-Width="100" ControlStyle-Width="95%" />
- <asp:CheckBoxField DataField="M_EHREN" HeaderText="Ehrenmitglied" SortExpression="M_EHREN" ItemStyle-Width="100" ControlStyle-Width="95%" />
- <asp:TemplateField HeaderText="Funktion" SortExpression="M_STATUS" ItemStyle-Width="100">
- <ItemTemplate>
- <asp:Label ID="LABEL1" runat="server" Text='<%# Eval("M_STATUS")%>' />
- </ItemTemplate>
- <EditItemTemplate>
- <asp:DropDownList ID="DropDownList1" AutoPostBack="true" OnRowDataBound="OnRowDataBound" OnSelectedIndexChanged="SelectedIndexChanged" runat="server" CssClass="Input" Width="100" SelectedValue='<%# Eval("M_STATUS")%>'>
- <asp:ListItem Value="" Text=" "></asp:ListItem>
- <asp:ListItem Value="Präsident" Text="Präsident"></asp:ListItem>
- <asp:ListItem Value="Präsidentin" Text="Präsidentin"></asp:ListItem>
- <asp:ListItem Value="Kassier" Text="Kassier"></asp:ListItem>
- <asp:ListItem Value="Kassierin" Text="Kassierin"></asp:ListItem>
- <asp:ListItem Value="Aktuar" Text="Aktuar"></asp:ListItem>
- <asp:ListItem Value="Aktuarin" Text="Aktuarin"></asp:ListItem>
- <asp:ListItem Value="1.Beisitzer/in" Text="1.Beisitzer/in"></asp:ListItem>
- <asp:ListItem Value="2.Beisitzer/in" Text="2.Beisitzer/in"></asp:ListItem>
- </asp:DropDownList>
- </EditItemTemplate>
- </asp:TemplateField>
- <asp:BoundField DataField="M_STATUS" HeaderText="Funktion" SortExpression="M_STATUS" ItemStyle-Width="250" ControlStyle-Width="95%" visible="true" />
- <asp:BoundField DataField="M_GEBURTSTAG" HeaderText="Geburtstag" SortExpression="M_GEBURTSTAG" ItemStyle-Width="250" ControlStyle-Width="95%" DataFormatString = "{0:dd/MM/yyyy}" ApplyFormatInEditMode="True" />
- <asp:BoundField DataField="M_AUSTRITT" HeaderText="Austritt per" SortExpression="M_AUSTRITT" ItemStyle-Width="250" ControlStyle-Width="95%" DataFormatString = "{0:dd/MM/yyyy}" ApplyFormatInEditMode="True" />
- <asp:CommandField ButtonType="button" HeaderText=" " ShowEditButton="True" ControlStyle-CssClass="Button" HeaderStyle-CssClass="Head" >
- </asp:CommandField>
- </Columns>
- </asp:GridView>
und folgenden Code Behind:
VB.NET-Quellcode
- Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
- CustomersSource2.ConnectionString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + Server.MapPath("~/opendirectory/OFZ.accdb")
- CustomersSource2.UpdateCommand = "update MITGLIEDER set M_NL = @M_NL, M_STATUS = @M_STATUS, M_EHREN = @M_EHREN, M_GEBURTSTAG = @M_GEBURTSTAG, M_AUSTRITT = @M_AUSTRITT, M_C_USER = '" + Session("USERNAME") + "', M_C_DATE = '" + Now() + "' where M_ID = @M_ID"
- End Sub
- Protected Sub OnRowDataBound(ByVal sender As Object, ByVal e As GridViewRowEventArgs)
- If e.Row.RowType = DataControlRowType.DataRow Then
- Dim drv As DataRowView = TryCast(e.Row.DataItem, DataRowView)
- Dim ddlCategories As DropDownList = TryCast(e.Row.FindControl("DropDownList1"), DropDownList)
- If ddlCategories IsNot Nothing Then
- ddlCategories.SelectedValue = drv("M_STATUS").ToString()
- End If
- End If
- End Sub
- Protected Sub SelectedIndexChanged(ByVal sender As Object, ByVal e As EventArgs)
- Dim ddl As DropDownList = DirectCast(sender, DropDownList)
- Dim row As GridViewRow = TryCast(ddl.NamingContainer, GridViewRow)
- Dim ddlv As String = DirectCast(sender, DropDownList).SelectedValue
- row.Cells(7).Text = ddlv
- End Sub
Eigentlich klappt alles mit ausnahme des DropDown. es wird zwar der richtige wert eingestellt beim editieren, wenn ich aber den Datensatz aktualisiere speichert er immer eine -1 oder 0 ab, und dies willkürlich...
Weiss jemand einen Rat dazu
Gruss
Markus
Am lernen...