[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 106
  • Last Modified:

Getting Compilation Error

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
HPH Y
Asked:
HPH Y
  • 2
1 Solution
 
Miguel OzSoftware EngineerCommented:
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
 
HPH YAuthor Commented:
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
 
HPH YAuthor Commented:
Miguel, Thanks for your help!!!!
0

Featured Post

Upgrade your Question Security!

Add Premium security features to your question to ensure its privacy or anonymity. Learn more about your ability to control Question Security today.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now