Solved

Getting Compilation Error

Posted on 2016-09-16
3
57 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 35

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

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

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

Lots of people ask this question on how to extend the “MembershipProvider” to make use of custom authentication like using existing database or make use of some other way of authentication. Many blogs show you how to extend the membership provider c…
This article discusses the ASP.NET AJAX ModalPopupExtender control. In this article we will show how to use the ModalPopupExtender control, how to display/show/call the ASP.NET AJAX ModalPopupExtender control from javascript, how to show/display/cal…
This is used to tweak the memory usage for your computer, it is used for servers more so than workstations but just be careful editing registry settings as it may cause irreversible results. I hold no responsibility for anything you do to the regist…
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …

813 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now