Gridview Edit Command Not Functioning Properly

sjesweak

Member
Joined
Dec 12, 2007
Messages
7
Programming Experience
3-5
I'm building a gridview dynamically for a work order page. Every work order looks different so I have to build my grid dynamically.

I have everything working fine in it except for the edit row command which when fired doesn't show the text boxes but does the postback. After all my reading on lots of websites I found that I have to create the templatefields or the edititemtemplates but can't get the code right to create it.

Below is my aspx page and I'm using the grdWO_Data for my data.

HTML:
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title>Work Order Display</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>    
       <asp:Label ID="lblTitle" CssClass="pageTitle" runat="server" Text="Work Order Display"></asp:Label>
        <asp:Label ID="lblWONum" CssClass="WONum" runat="server" Text="WO # "></asp:Label>
        <asp:Label ID="lblWONumText" CssClass="WONumText" runat="server" Text="Value"></asp:Label>
        <asp:Label ID="lblWOType" CssClass="WOType" runat="server" Text="Type"></asp:Label>
        <asp:Label ID="lblWOTypeID" CssClass="WOTypeID" runat="server" Text="0"></asp:Label>
        <asp:Label ID="lblWOTypeText" CssClass="WOTypeText" runat="server" Text="Type"></asp:Label>
        <asp:Label ID="lblCreatedBy" CssClass="WOCreatedBy" runat="server" Text="Created By"></asp:Label>
        <asp:Label ID="lblCreatedByID" CssClass="WOCreatedByID" runat="server" Text="User"></asp:Label>
        <asp:Label ID="lblDept" CssClass="UserDept" runat="server" Text="Dept"></asp:Label>
        <asp:DropDownList ID="ddlDept" CssClass="DeptSelect" runat="server" AutoPostBack="True" DataSourceID="SQLRS"
 DataTextField="DEPT_DESC" DataValueField="DEPT_ID">
</asp:DropDownList>
<asp:SqlDataSource ID="SQLRS" runat="server" ConnectionString="<%$ ConnectionStrings:APSConnectionString %>"
            SelectCommand="SELECT [DEPT_ID], [DEPT_DESC] FROM [tbl_LAB_WO_DEPTS] ORDER BY [DEPT_ID]">
        </asp:SqlDataSource>
        <asp:GridView ID="grdWO_Data" CssClass="WO_Data" runat="server" AutoGenerateColumns="True" DataKeyNames="SAMPLE ID">
        <HeaderStyle CssClass="WO_DataHeader"></HeaderStyle>        
        <RowStyle CssClass="WO_DataRow" />        
        </asp:GridView>
        <asp:Panel ID="pnlInsertData" CssClass="InsertData" runat="server"></asp:Panel> 
        <asp:Button ID="btnReturn" CssClass="btnReturn" runat="server" Text="Return to Main" CausesValidation="False" />
        <asp:Label  ID="lblDataChanged" runat="server" Text="NO" Visible="False"></asp:Label>  
        <asp:GridView ID="GridView1" runat="server" >
            <Columns>
                
            </Columns>
        </asp:GridView>      
        </div>
    </form>    
</body>
</html>

Here is the function code where the grid is bound from the dataset.

VB.NET:
Dim ds As DataSet
        Dim params() As SqlParameter

        Select Case WOType
            Case 2
                ReDim params(0)

                params(0) = New SqlParameter("@WO_ID", 31)
                ds = srv.executeStoredProc(Application("sqlStr"), "LAB_Select_Carbon_WO_Samples", params, "WO_SAMPLES")

                Dim dc As DataColumn
                If ds.Tables.Count > 0 Then
                    'Building all the columns in the table. 
                    For Each dc In ds.Tables(0).Columns
                        Dim bField As New BoundField

                        'Initalize the DataField value.
                        bField.DataField = dc.ColumnName

                        'Initialize the HeaderText field value. 
                        bField.HeaderText = dc.ColumnName
                        'Add the newly created bound field to the GridView. 
                        GridView1.Columns.Add(bField)
                    Next
                End If
                GridView1.AutoGenerateEditButton = True
                GridView1.CssClass = "test"
                GridView1.DataSource = ds.Tables(0)
                GridView1.DataBind()
        End Select
 
Last edited by a moderator:
Back
Top