Click here to Skip to main content
15,887,302 members
Home / Discussions / ASP.NET
   

ASP.NET

 
QuestionArchitecture similar to asp.net boilerplate Pin
Charlie brown 71112-Mar-18 20:47
Charlie brown 71112-Mar-18 20:47 
QuestionProcess master detail JSON with WCF Pin
Priyanka Kale9-Mar-18 0:08
Priyanka Kale9-Mar-18 0:08 
QuestionData Access In Models & Repositories Pin
Priyanka Kale7-Mar-18 22:42
Priyanka Kale7-Mar-18 22:42 
AnswerRe: Data Access In Models & Repositories Pin
Richard MacCutchan7-Mar-18 23:09
mveRichard MacCutchan7-Mar-18 23:09 
AnswerRe: Data Access In Models & Repositories Pin
Nagaraj Muthuchamy12-Mar-18 22:57
professionalNagaraj Muthuchamy12-Mar-18 22:57 
QuestionAn error occurred while receiving the HTTP response to https://localhost:44301/XXXXXXX.svc. Pin
indian1437-Mar-18 13:36
indian1437-Mar-18 13:36 
SuggestionRe: An error occurred while receiving the HTTP response to https://localhost:44301/XXXXXXX.svc. Pin
Richard Deeming8-Mar-18 9:06
mveRichard Deeming8-Mar-18 9:06 
QuestionUnable to cast object of type 'System.Web.UI.WebControls.TemplateField' to type 'System.Web.UI.WebControls.CommandField' Pin
samflex7-Mar-18 6:49
samflex7-Mar-18 6:49 
I have a markup page that was using CommandField delete button. This was later replaced with regular button control.

Code:

   <table>
      <tr>
        <td>
          <asp:gridview ID="Gridview1" RowStyle-Wrap="false" gridlines="None" CssClass="responsiveTable1" runat="server" ShowFooter="true" AutoGenerateColumns="false" OnRowDeleting="Gridview1_RowDeleting">
            <Columns>
            <asp:BoundField DataField="RowNumber" Visible="false" HeaderText="Row Number" />
            <asp:TemplateField HeaderText="Name">
             <headerstyle horizontalalign="Left" />
                <ItemTemplate>
                    <asp:TextBox ID="txtsourcename" placeholder="Name...(e.g, Jane Doe)" runat="server" style="width:375px;" AutoPostBack="true" class="form-control textClass" OnTextChanged="txtsourcename_TextChanged"></asp:TextBox><br />
                    <asp:CheckBox ID="grid1Details" ClientIDMode="Static" runat="server" Checked="false" AutoPostBack="true" OnCheckedChanged="Grid1CheckChanged" /><span style="color:#ff0000">*Check this box if N/A</span>
                </ItemTemplate>
            </asp:TemplateField>
            <asp:TemplateField HeaderText="Address">
            <ItemStyle HorizontalAlign="Left"></ItemStyle>
                <ItemTemplate>
                    <asp:TextBox ID="txtsourceaddress" placeholder="Address..." runat="server" style="width:375px;" class="form-control textClass"></asp:TextBox><br /><br />
                </ItemTemplate>
            </asp:TemplateField>
            <asp:TemplateField HeaderText="">
                <ItemTemplate>
                 <asp:Button ID="ButtonAdd" runat="server" Text="Add" 
                        onclick="ButtonAdd_Click" CssClass="grvAddButton" /><br /><br /><br>
                </ItemTemplate>
            </asp:TemplateField>
            <asp:TemplateField HeaderText="">
                <ItemTemplate>
                 <asp:Button ID="sourceDelete" runat="server" Text="Delete" CommandName="Delete"
                         CssClass="grvDelButton" OnClientClick="return confirm('Are you sure you want to remove this row?')"  /> <br /><br /><br />
                </ItemTemplate>
            </asp:TemplateField> 
<%--           <asp:CommandField ShowDeleteButton="True"><ControlStyle CssClass="grvDelButton" /></asp:CommandField>--%>
            </Columns>
          </asp:gridview>
        </td>
     </tr>
   </table>


The delete button is used to delete any additional / unwanted rows created in dynamically generated row in GridView.

Since the commandField delete button was replaced, the VB the engineers the delete action is now throwing an error:
Unable to cast object of type 'System.Web.UI.WebControls.TemplateField' to type 'System.Web.UI.WebControls.CommandField'

Does anyone know how to modify this to reflect the button control ID used in markup instead of CommandField?

PHP
Protected Sub GrvSource_RowDataBound(sender As Object, e As GridViewRowEventArgs)
        If e.Row.RowType = DataControlRowType.Header Then
            If e.Row.RowIndex = -1 Then
                DirectCast(DirectCast(e.Row.Cells(4), DataControlFieldCell).ContainingField, CommandField).ShowDeleteButton = False
            End If
        Else
            If Convert.ToInt32(ViewState("rowIndex" & 0)) = e.Row.RowIndex Then
                DirectCast(DirectCast(e.Row.Cells(4), DataControlFieldCell).ContainingField, CommandField).ShowDeleteButton = True
            End If
        End If
    End Sub



Thank in advance
AnswerRe: Unable to cast object of type 'System.Web.UI.WebControls.TemplateField' to type 'System.Web.UI.WebControls.CommandField' Pin
Richard Deeming7-Mar-18 8:40
mveRichard Deeming7-Mar-18 8:40 
GeneralRe: Unable to cast object of type 'System.Web.UI.WebControls.TemplateField' to type 'System.Web.UI.WebControls.CommandField' Pin
samflex7-Mar-18 9:32
samflex7-Mar-18 9:32 
Questioncreating organisational charts Pin
Member 137048122-Mar-18 0:08
Member 137048122-Mar-18 0:08 
AnswerRe: creating organisational charts Pin
David Mujica2-Mar-18 10:43
David Mujica2-Mar-18 10:43 
QuestionWeb API: Can we generate token without using identity Pin
Mou_kol27-Feb-18 22:53
Mou_kol27-Feb-18 22:53 
AnswerRe: Web API: Can we generate token without using identity Pin
Nathan Minier5-Mar-18 2:00
professionalNathan Minier5-Mar-18 2:00 
GeneralRe: Web API: Can we generate token without using identity Pin
Mou_kol5-Mar-18 21:13
Mou_kol5-Mar-18 21:13 
General.NET Core fits in the .NET Ecosystem Pin
Priyanka Kale26-Feb-18 23:15
Priyanka Kale26-Feb-18 23:15 
QuestionAshraf Pin
Member 1206559124-Feb-18 23:53
Member 1206559124-Feb-18 23:53 
AnswerRe: Ashraf Pin
Richard MacCutchan25-Feb-18 3:47
mveRichard MacCutchan25-Feb-18 3:47 
AnswerRe: Ashraf Pin
ZurdoDev26-Feb-18 2:04
professionalZurdoDev26-Feb-18 2:04 
QuestionRe: Ashraf Pin
ZurdoDev26-Feb-18 2:05
professionalZurdoDev26-Feb-18 2:05 
QuestionASP.Net MVC: How to show checkboxes selection in webgrid column after postback data Pin
Mou_kol19-Feb-18 7:17
Mou_kol19-Feb-18 7:17 
Questionread json file using newtonsoft.json Pin
alpacaheng18-Feb-18 21:49
alpacaheng18-Feb-18 21:49 
SuggestionRe: read json file using newtonsoft.json Pin
Richard MacCutchan18-Feb-18 22:26
mveRichard MacCutchan18-Feb-18 22:26 
AnswerRe: read json file using newtonsoft.json Pin
F-ES Sitecore19-Feb-18 0:08
professionalF-ES Sitecore19-Feb-18 0:08 
QuestionHow to update local json file? Pin
alpacaheng18-Feb-18 21:16
alpacaheng18-Feb-18 21:16 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.