Hi!
I've have a gridview on my site:
<asp:GridView ID="GridView1" runat="server" AlternatingRowStyle-CssClass="gridview_alter"
AutoGenerateColumns="False" EmptyDataText=" " GridLines="None" OnRowCancelingEdit="RowCancelingEdit"
OnRowDataBound="GridView1_RowDataBound" OnRowDeleting="RowDeleting" OnRowEditing="RowEditing"
OnRowUpdating="RowUpdating" ShowHeaderWhenEmpty="True" Width="820px">
<AlternatingRowStyle CssClass="gridview_alter" />
<Columns>
<asp:TemplateField HeaderText="Leírás" Visible="false" />
<asp:BoundField DataField="Description" HeaderStyle-Width="150" HeaderText="Leírás" HtmlEncode="false">
<HeaderStyle Width="150px" />
</asp:BoundField>
<asp:BoundField HeaderText="Kritérium" DataField="IndexNumber" />
<asp:BoundField DataField="Weight" HeaderStyle-Width="50" HeaderText="Súly">
<HeaderStyle Width="50px" />
</asp:BoundField>
<asp:TemplateField HeaderStyle-Width="100" HeaderText="Cél típusa">
<EditItemTemplate>
<asp:DropDownList ID="DropDownList1"
runat="server" AutoPostBack="False">
</asp:DropDownList>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="lblGoalType" runat="server"></asp:Label>
</ItemTemplate>
<HeaderStyle Width="100px" />
</asp:TemplateField>
<asp:CommandField DeleteText="Törlés" HeaderStyle-Width="60" ShowDeleteButton="true">
<HeaderStyle Width="60px" />
</asp:CommandField>
<asp:CommandField CancelText="Mégse" DeleteText="Törlés" EditText="Szerkesztés"
HeaderStyle-Width="60" ShowEditButton="True" UpdateText="Frissítés"
ValidationGroup="Leírás, Súly">
<HeaderStyle Width="60px" />
</asp:CommandField>
</Columns>
</asp:GridView>
The "Cél típusa" column gets data from a list, that contains 1, 2 or 3. In code behind:
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
Goal row = (Goal)e.Row.DataItem;
Label lblGoalType = (Label)e.Row.FindControl("lblGoalType");
e.Row.Cells[0].Text = e.Row.Cells[0].Text.Replace("\n", "<br />");
switch (row.GoalTypeId)
{
case 1:
lblGoalType.Text = "Személyes";
break;
case 2:
lblGoalType.Text = "Egyéni";
break;
case 3:
lblGoalType.Text = "Szervezeti";
break;
}
}
if (e.Row.RowType == DataControlRowType.DataRow)
{
LinkButton db = (LinkButton)e.Row.Cells[5].Controls[0];
db.OnClientClick = "return confirm('Biztos benne, hogy törölni akarja a kiválasztott célt?');";
}
}
I give strings to the specified numbers.
My problem is that I need to update the cells with a dropdownlist, but when u press the Edit button on the gridview i get an error msg: Object reference not set to an instance of an object.
I am stuck here, got no idea, please help.