GRIDVIEW EDIT - CODE BIND

I am having issues with Gridview1 and my code behind.    When I convert field "Status1" to a template field in order to utilize a dropdown list my code behind will not fire.   The code behind Onrowdatabound event fires normal when it is left as the standard textbox field and no template insertion is utilized in the gridview when selecting edit.

Can someone assist?

<asp:GridView ID="GridView1" onrowdatabound="GridView1_RowDataBound" 
                        runat="server" EnableModelValidation="True" 
                        Width="375px" AllowSorting="True" AutoGenerateColumns="False" 
                        DataKeyNames="ID" DataSourceID="SqlDataSource1" 
                        ForeColor="White" BackColor="#006699" BorderColor="Black" 
                        style="font-size: medium">
                        <Columns>
                            <asp:CommandField DeleteText="Del" ShowDeleteButton="True" 
                                ShowEditButton="True">
                            <HeaderStyle HorizontalAlign="Left" Width="25px" />
                            <ItemStyle HorizontalAlign="Left" Width="25px" ForeColor="Black" />
                            </asp:CommandField>

                        <asp:templatefield HeaderText="No.">
&#9;&#9;&#9;&#9;&#9;&#9;&#9;<ItemTemplate>
&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;<%# Container.DataItemIndex + 1 %>
&#9;&#9;&#9;&#9;&#9;&#9;&#9;</ItemTemplate>
&#9;&#9;&#9;&#9;&#9;&#9;&#9;<HeaderStyle Font-Underline="True" Width="25px" HorizontalAlign="Center" 
                                ForeColor="White" />
&#9;&#9;&#9;&#9;&#9;&#9;&#9;<ItemStyle HorizontalAlign="Center" Wrap="False" ForeColor="Black" 
                                Width="25px" />
&#9;&#9;&#9;&#9;&#9;&#9;</asp:templatefield>
                        
                            <asp:TemplateField HeaderText="Ship" SortExpression="Ship1">
                                <ItemTemplate>
                                    <asp:Label ID="Label2" runat="server" Text='<%# Bind("Ship1") %>'></asp:Label>
                                </ItemTemplate>
                                <EditItemTemplate>
                                    <asp:DropDownList ID="DropDownList1" runat="server" 
                                        DataSourceID="SqlDataSource111" DataTextField="Ship" DataValueField="Ship" 
                                        Height="22px" SelectedValue='<%# Bind("Ship1") %>' Width="92px">
                                    </asp:DropDownList>
                                    <asp:SqlDataSource ID="SqlDataSource111" runat="server" 
                                        ConnectionString="<%$ ConnectionStrings: %>" 
                                        SelectCommand="SELECT DISTINCT [Ship] FROM [DropListData] ORDER BY [Ship]"></asp:SqlDataSource>
                                </EditItemTemplate>
                                <HeaderStyle HorizontalAlign="Center" Width="45px" />
                                <ItemStyle ForeColor="Black" HorizontalAlign="Center" Width="45px" />
                            </asp:TemplateField>
                            <asp:TemplateField HeaderText="DepTime" SortExpression="DepTime1">
                                <ItemTemplate>
                                    <asp:Label ID="Label3" runat="server" Text='<%# Bind("DepTime1") %>'></asp:Label>
                                </ItemTemplate>
                                <EditItemTemplate>
                                    <asp:TextBox ID="TextBox3" runat="server" Text='<%# Bind("DepTime1") %>' 
                                        Width="88px"></asp:TextBox>
                                    <br />
                                    <asp:RegularExpressionValidator ID="Validator4" runat="server" 
                                        ControlToValidate="TextBox3" CssClass="style14" 
                                        ErrorMessage="(24:00 format)" Font-Bold="False" Font-Size="Small" 
                                        ValidationExpression="^(20|21|22|23|[01]\d|\d)(([:][0-5]\d){1,2})$" />
                                </EditItemTemplate>
                                <HeaderStyle HorizontalAlign="Center" Width="45px" />
                                <ItemStyle ForeColor="Black" HorizontalAlign="Center" Width="45px" />
                            </asp:TemplateField>
                            <asp:TemplateField HeaderText="Gate" SortExpression="GT">
                                <EditItemTemplate>
                                    <asp:TextBox ID="TextBox1" runat="server" Height="19px" 
                                        Text='<%# Bind("GT") %>' Width="72px"></asp:TextBox>
                                </EditItemTemplate>
                                <ItemTemplate>
                                    <asp:Label ID="Label4" runat="server" Text='<%# Bind("GT") %>'></asp:Label>
                                </ItemTemplate>
                                <HeaderStyle HorizontalAlign="Center" Width="45px" />
                                <ItemStyle ForeColor="Black" HorizontalAlign="Center" Width="45px" />
                            </asp:TemplateField>
                            <asp:TemplateField HeaderText="Dest City" SortExpression="Dest1">
                                <EditItemTemplate>
                                    <asp:DropDownList ID="DropDownList3" runat="server" 
                                        DataSourceID="SqlDataSource21" DataTextField="Station" DataValueField="Station" 
                                        Height="22px" SelectedValue='<%# Bind("Dest1") %>' Width="104px">
                                    </asp:DropDownList>
                                    <asp:SqlDataSource ID="SqlDataSource21" runat="server" 
                                        ConnectionString="<%$ ConnectionStrings: %>" 
                                        SelectCommand="SELECT [Station] FROM [DropListData]"></asp:SqlDataSource>
                                </EditItemTemplate>
                                <ItemTemplate>
                                    <asp:Label ID="Label1" runat="server" Text='<%# Bind("Dest1") %>'></asp:Label>
                                </ItemTemplate>
                                <HeaderStyle HorizontalAlign="Center" Width="45px" />
                                <ItemStyle HorizontalAlign="Center" Width="45px" ForeColor="Black" />
                            </asp:TemplateField>
                        
                            <asp:TemplateField HeaderText="Acft Status" SortExpression="Status1">
                                <EditItemTemplate>
                                    <asp:DropDownList ID="DropDownList6" runat="server" AutoPostBack="True" 
                                        Height="22px" SelectedValue='<%# Bind("Status1") %>' Width="82px">
                                        <asp:ListItem></asp:ListItem>
                                        <asp:ListItem>RDY</asp:ListItem>
                                        <asp:ListItem>BOB</asp:ListItem>
                                        <asp:ListItem>INSP</asp:ListItem>
                                        <asp:ListItem>WKG</asp:ListItem>
                                        <asp:ListItem>AOG</asp:ListItem>
                                    </asp:DropDownList>
                                </EditItemTemplate>
                                <ItemTemplate>
                                    <asp:Label ID="Label5" runat="server" Text='<%# Bind("Status1") %>'></asp:Label>
                                </ItemTemplate>
                                <HeaderStyle HorizontalAlign="Center" Width="45px" />
                                <ItemStyle ForeColor="Black" HorizontalAlign="Center" Width="45px" />
                            </asp:TemplateField>
                        </Columns>
                    </asp:GridView>

Open in new window





public partial class BigBoardDisp : System.Web.UI.Page
{

    protected void GridView1_RowDataBound (object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.DataRow)
            if (e.Row.Cells[6].Text == "AOG" || e.Row.Cells[6].Equals(DBNull.Value))
            {
                e.Row.BackColor = System.Drawing.Color.Red;
            }

            else if (e.Row.Cells[6].Text == "RDY")
            {
                e.Row.BackColor = System.Drawing.Color.Aqua;
            }

            else if (e.Row.Cells[6].Text == "WKG")
            {
                e.Row.BackColor = System.Drawing.Color.LightSkyBlue;
            }

            else if (e.Row.Cells[6].Text == "INSP")
            {
                e.Row.BackColor = System.Drawing.Color.Yellow;
            }

            else if (e.Row.Cells[6].Text == "BOB")
            {
                e.Row.BackColor = System.Drawing.Color.Lime;
            }

    }

Open in new window

BOEING39Asked:
Who is Participating?
 
Vadim RappConnect With a Mentor Commented:
It's not entire code, entire code would be the whole solution complete with the database file the gridview takes its data from. We should be able to open it, and actually run it and see how it behaves.

Here's an example of sample solution together with its datasource.

It's understood that your real database may contain real data you don't want to share, but for the purpose of showing the problem on e-e, you may want to isolate it to simple separate solution that would have only the elements necessary to show the problem.
0
 
Vadim RappCommented:
It's difficult for us to see what's going on; you posted one piece of the code, and even that piece has things that we cannot run, such as connection. Either explain the problem assuming that we have no idea about your application, or upload whole solution together with the data source it's using, so we can reproduce.

The event "Onrowdatabound " fires on each row of the gridview, as the name suggests, so it does not matter what controls are within the row.
0
 
BOEING39Author Commented:
Ok, I have attached the entire code.   An item to note, As soon as I identify or change the "Status1" column to a Template field, I am losing all my code behind formatting which is setup to change the row color based on the "Status1" value.   If I leave the field un-modified, or just a TextBox field the formatting works or the code behind fires.  I have modified Gridview1 in the attached and left Gridview2 un-modified so you can see what is occurring.  However, both "Status1" and "Status2" columns need to have a dropdown box with selectable values that can be changed by the user using the EDIT function.
BigBoardDisp.aspx
BigBoardDisp.aspx.cs
0
 
BOEING39Author Commented:
Thanks for the reference
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.