locked
Error - Cannot implicitly convert type string to int RRS feed

  • Question

  • User-1499457942 posted

    Hi

      I have to get Boundfield No value in Function . I am trying like below but not working

    protected void ibtnDelete_Click(object sender, ImageClickEventArgs e)
            {
                GridViewRow gvRow = (GridViewRow)((ImageButton)sender).NamingContainer;
                Int32 No = gvwInflator.Rows[gvRow.RowIndex].Cells[0].Text.ToString();
            }
    
    
    
    <Columns>
                                        <asp:BoundField DataField="No" HeaderText="No" InsertVisible="False" ItemStyle-CssClass="hiddencol" HeaderStyle-CssClass="hiddencol" />
                                        <asp:BoundField HeaderText="Inflator" DataField="Inflator" />
    
                                        <asp:TemplateField HeaderText="Action">
                                            <ItemTemplate>
                                               <asp:ImageButton ID="ibtnDelete" runat="server" imageUrl="/Images/btn-delete.jpg"
                                                  OnClientClick="javascript:return confirm('Do you want to delete it?');" OnClick="ibtnDelete_Click" />
                                            </ItemTemplate>
                                        </asp:TemplateField>
                                    </Columns>

    Thanks

    Sunday, August 12, 2018 4:13 PM

Answers

  • User475983607 posted
    The code is specifically trying to assign a string to an Int32. Use int.Parse or int.TryParse to convert the string to an int. Keep in mind that you have had this issue several times. Please learn how to debug your code.
    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Sunday, August 12, 2018 4:21 PM