Solved

Getting Compilation Error

Posted on 2016-09-16
3
71 Views
Last Modified: 2016-09-23
Hi, I am trying to edit/update the gridview without using edit and update buttons. I am not sure how to achieve this yet. I converted the vb code below from c# and got a compilation error. Can someone help? Thank you!


Compilation Error

Compiler Error Message: BC30456: 'GridView1_RowCommand' is not a member of 'ASP.itrequest_aspx'.

Source Error:


Line 32: <asp:LinkButton ID="lnkDummy" runat="server"></asp:LinkButton>
Line 33:
Line 34: <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False"
Line 35:             BackColor="White" BorderColor="#DEDFDE" BorderStyle="None" BorderWidth="1px"
Line 36:             CellPadding="4" ForeColor="Black"

<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False"
            BackColor="White" BorderColor="#DEDFDE" BorderStyle="None" BorderWidth="1px"
            CellPadding="4" ForeColor="Black"
            GridLines="Vertical" OnRowCreated="GridView1_RowCreated" OnRowCommand="GridView1_RowCommand">
            <RowStyle BackColor="#F7F7DE" />
            <Columns>
                <asp:BoundField DataField="Room" HeaderText="Room" SortExpression="Room" />
                <asp:TemplateField HeaderText="TextBox">
                <ItemTemplate>
                    <asp:TextBox runat="server" ID="txtfocus" AutoPostBack="true"></asp:TextBox>
                </ItemTemplate>
                <HeaderStyle HorizontalAlign="Center" />
                    <ItemStyle HorizontalAlign="Center" />
                </asp:TemplateField>
            </Columns>
            <FooterStyle BackColor="#CCCC99" />
            <PagerStyle BackColor="#F7F7DE" ForeColor="Black" HorizontalAlign="Right" />
            <SelectedRowStyle BackColor="#CE5D5A" Font-Bold="True" ForeColor="White" />
            <HeaderStyle BackColor="#6B696B" Font-Bold="True" ForeColor="White" />
            <AlternatingRowStyle BackColor="White" />
        </asp:GridView>


Protected Sub GridView1_RowCreated(sender As Object, e As GridViewRowEventArgs)
        If e.Row.RowType = DataControlRowType.DataRow Then
            If e.Row.FindControl("txtfocus") IsNot Nothing Then
                Dim txtfocus As TextBox = DirectCast(e.Row.FindControl("txtfocus"), TextBox)
                AddHandler txtfocus.TextChanged, New EventHandler(AddressOf txtfocus_TextChanged)
            End If
        End If
    End Sub

    Private Sub txtfocus_TextChanged(sender As Object, e As EventArgs)
        'get current textbox
        Dim txt As TextBox = DirectCast(sender, TextBox)
        'find other controls in the same row
        Dim gvr As GridViewRow = DirectCast(txt.Parent.Parent, GridViewRow)
        Dim txtone As TextBox = DirectCast(gvr.FindControl("txtone"), TextBox)
        'update to database
    End Sub
0
Comment
Question by:HPH Y
  • 2
3 Comments
 
LVL 36

Accepted Solution

by:
Miguel Oz earned 500 total points
ID: 41802519
Your code behind does not have "GridView1_RowCommand" defined.
One possible solution is to delete OnRowCommand event from aspx file:
Replace:
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" 
             BackColor="White" BorderColor="#DEDFDE" BorderStyle="None" BorderWidth="1px" 
             CellPadding="4" ForeColor="Black" 
             GridLines="Vertical" OnRowCreated="GridView1_RowCreated" OnRowCommand="GridView1_RowCommand">

Open in new window

with:
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" 
             BackColor="White" BorderColor="#DEDFDE" BorderStyle="None" BorderWidth="1px" 
             CellPadding="4" ForeColor="Black" 
             GridLines="Vertical" OnRowCreated="GridView1_RowCreated">

Open in new window

0
 

Author Comment

by:HPH Y
ID: 41804829
Thanks Miguel! The error is gone. the problem now is when I entered something in the textbox, the DirectCast does not cast any value at all. Any suggestions? Thank you.
0
 

Author Closing Comment

by:HPH Y
ID: 41812316
Miguel, Thanks for your help!!!!
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…

685 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question