Click here to Skip to main content
14,766,830 members
Home » Discussions » ASP.NET
   

ASP.NET

 
QuestionArchitecture similar to asp.net boilerplate Pin
Charlie brown 71112-Mar-18 21:47
MemberCharlie brown 71112-Mar-18 21:47 
QuestionProcess master detail JSON with WCF Pin
Priyanka Kale9-Mar-18 1:08
MemberPriyanka Kale9-Mar-18 1:08 
QuestionData Access In Models & Repositories Pin
Priyanka Kale7-Mar-18 23:42
MemberPriyanka Kale7-Mar-18 23:42 
AnswerRe: Data Access In Models & Repositories Pin
Richard MacCutchan8-Mar-18 0:09
mveRichard MacCutchan8-Mar-18 0:09 
AnswerRe: Data Access In Models & Repositories Pin
Nagaraj Muthuchamy12-Mar-18 23:57
professionalNagaraj Muthuchamy12-Mar-18 23:57 
QuestionAn error occurred while receiving the HTTP response to https://localhost:44301/XXXXXXX.svc. Pin
indian1437-Mar-18 14:36
Memberindian1437-Mar-18 14:36 
SuggestionRe: An error occurred while receiving the HTTP response to https://localhost:44301/XXXXXXX.svc. Pin
Richard Deeming8-Mar-18 10:06
mveRichard Deeming8-Mar-18 10:06 
QuestionUnable to cast object of type 'System.Web.UI.WebControls.TemplateField' to type 'System.Web.UI.WebControls.CommandField' Pin
samflex7-Mar-18 7:49
Membersamflex7-Mar-18 7: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?

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