本文介绍了使用boundfield更新gridview的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好,



我希望你们都做得很好。

我有一个关于使用BoundField更新GridView的问题。

我目前正在做的是我在GridView中添加了一个编辑按钮,一旦我点击它就会给我编辑字段并且更新取消按钮。

取消编辑按钮工作正常,但我想更新工作也好。



以下是我的HTML代码:



< ; asp:GridView ID =gvSubmittedCasesrunat =serverOnRowEditing =gvSubmittedCases_RowEditingOnRowUpdating =gvSubmittedCases_RowUpdating
OnRowCancelingEdit =gvSubmittedCases_RowCancelingEditCellPadding =4GridLines =NoneWidth =100%AutoGenerateColumns =FalseForeColor =#333333>
< AlternatingRowStyle BackColor =WhiteForeColor =#284775/>
< Columns>
< asp:BoundField DataField =SubmittedDateReadOnly =trueHeaderText =SubmittedDateItemStyle-Width =100SortExpression =SubmittedBy>
< / asp:BoundField>
< asp:BoundField DataField =SubmittedByVisible =trueReadOnly =trueHeaderText =Submitted ByItemStyle-Width =150SortExpression =Transaction Amount>
< / asp:BoundField>
<% - < asp:BoundField DataField =Display_NameVisible =trueHeaderText =Display NameItemStyle-Width =150SortExpression =Display Name>
< / asp:BoundField> - %>
< asp:BoundField DataField =CardNoHeaderText =卡号ItemStyle-Width =100SortExpression =CardNo>
< / asp:BoundField>
< asp:BoundField DataField =CardTypeReadOnly =trueHeaderText =Card TypeItemStyle-Width =100SortExpression =CardType>
< / asp:BoundField>
< asp:BoundField DataField =FraudTypeHeaderText =欺诈类型ItemStyle-Width =150SortExpression =FraudType>
< / asp:BoundField>
< asp:BoundField DataField =CaseIDVisible =trueReadOnly =trueHeaderText =CaseIDItemStyle-Width =150SortExpression =CaseID>
< / asp:BoundField>
< asp:BoundField DataField =RegionVisible =trueHeaderText =RegionItemStyle-Width =150SortExpression =Region>
< / asp:BoundField>
< asp:BoundField DataField =AuthorisationCodeVisible =trueReadOnly =trueHeaderText =Auth CodeItemStyle-Width =150SortExpression =Auth Code>
< / asp:BoundField>
< asp:BoundField DataField =TransactionDateVisible =trueHeaderText =Transaction DateItemStyle-Width =150SortExpression =TransactionDate>
< / asp:BoundField>
< asp:BoundField DataField =TransactionAmountVisible =TRUEHeaderText =Transaction AmountItemStyle-Width =150SortExpression =Transaction Amount>
< / asp:BoundField>
< asp:TemplateField>
< ItemTemplate>
< asp:Button ID =btnEditrunat =serverText =EditCommandName =Edit/>
< / ItemTemplate>
< EditItemTemplate>
< asp:Button ID =btnUpdaterunat =serverText =UpdateCommandName =Update/>
< asp:Button ID =btnCancelrunat =serverText =CancelCommandName =Cancel/>
< / EditItemTemplate>
< / asp:TemplateField>

< / Columns>







这是Code Behind。





 private void CaseView()
{
BusinessLayer k = new BusinessLayer( );
DataTable dt = k.ViewCases(UserID,UserType);
if(dt.Rows.Count> = 0)
{
gvSubmittedCases.DataSource = dt;
gvSubmittedCases.DataBind();
}
else
lblCases.Text =没有找到案例;
}

protected void gvSubmittedCases_RowEditing(object sender,GridViewEditEventArgs e)
{
gvSubmittedCases.EditIndex = e.NewEditIndex;
CaseView();
}





 protected void gvSubmittedCases_RowCancelingEdit(object sender,GridViewCancelEditEventArgs e)
{
gvSubmittedCases.EditIndex = -1;
CaseView();

}







此外,还有一个字段 FraudType 我想在用户点击编辑时丢弃。



我希望我已经清除了我的问题。

您可以询问是否需要清除任何东西。



注意:



我正在使用存储过程更新数据库,在SQL中





谢谢



我尝试了什么:



我搜索了网页,但是没有适当的解决方案对于BoundField +存储过程

解决方案

Hello,

I hope you all are doing great.
I have a question regarding Update GridView using BoundField.
What i am doing currently is i have added a edit button in the GridView and once i click on it it gives me editable fields and update and cancel button with it.
Cancel and Edit buttons are working fine but i want update to work as well.

Below is my HTML Code:

<asp:GridView ID="gvSubmittedCases" runat="server" OnRowEditing="gvSubmittedCases_RowEditing" OnRowUpdating="gvSubmittedCases_RowUpdating"  
                    OnRowCancelingEdit="gvSubmittedCases_RowCancelingEdit"   CellPadding="4" GridLines="None" Width="100%" AutoGenerateColumns="False"  ForeColor="#333333" >  
                        <AlternatingRowStyle BackColor="White" ForeColor="#284775" />
                        <Columns>
                            <asp:BoundField DataField="SubmittedDate" ReadOnly="true" HeaderText="SubmittedDate" ItemStyle-Width="100" SortExpression="SubmittedBy" >
                            </asp:BoundField>
                            <asp:BoundField DataField="SubmittedBy" Visible="true" ReadOnly="true" HeaderText="Submitted By" ItemStyle-Width="150" SortExpression="Transaction Amount" >
                            </asp:BoundField>
                            <%--<asp:BoundField DataField="Display_Name" Visible="true" HeaderText="Display Name" ItemStyle-Width="150" SortExpression="Display Name" >
                            </asp:BoundField>--%>
                            <asp:BoundField DataField="CardNo" HeaderText="Card Number" ItemStyle-Width="100" SortExpression="CardNo" >
                            </asp:BoundField>
                            <asp:BoundField DataField="CardType" ReadOnly="true" HeaderText="Card Type" ItemStyle-Width="100" SortExpression="CardType" >
                            </asp:BoundField>
                            <asp:BoundField DataField="FraudType" HeaderText="Fraud Type" ItemStyle-Width="150" SortExpression="FraudType" >
                            </asp:BoundField>
                            <asp:BoundField DataField="CaseID" Visible="true" ReadOnly="true" HeaderText="CaseID" ItemStyle-Width="150" SortExpression="CaseID" >
                            </asp:BoundField>
                            <asp:BoundField DataField="Region"  Visible="true" HeaderText="Region" ItemStyle-Width="150" SortExpression="Region" >
                            </asp:BoundField>
                            <asp:BoundField DataField="AuthorisationCode"  Visible="true" ReadOnly="true" HeaderText="Auth Code" ItemStyle-Width="150" SortExpression="Auth Code" >
                            </asp:BoundField>
                            <asp:BoundField DataField="TransactionDate" Visible="true" HeaderText="Transaction Date" ItemStyle-Width="150" SortExpression="TransactionDate" >
                            </asp:BoundField>
                            <asp:BoundField DataField="TransactionAmount" Visible="TRUE" HeaderText="Transaction Amount" ItemStyle-Width="150" SortExpression="Transaction Amount" >
                            </asp:BoundField>
                            <asp:TemplateField>
                                <ItemTemplate>
                                    <asp:Button ID="btnEdit" runat="server" Text="Edit" CommandName="Edit" />
                                </ItemTemplate>
                                <EditItemTemplate>
                                    <asp:Button ID="btnUpdate" runat="server" Text="Update" CommandName="Update" />
                                    <asp:Button ID="btnCancel" runat="server" Text="Cancel" CommandName="Cancel" />
                                    </EditItemTemplate>
                                </asp:TemplateField>
                           
                            </Columns>




And this is Code Behind.


private void CaseView()
  {
      BusinessLayer k = new BusinessLayer();
      DataTable dt = k.ViewCases(UserID,UserType);
      if (dt.Rows.Count >= 0)
      {
          gvSubmittedCases.DataSource = dt;
          gvSubmittedCases.DataBind();
      }
      else
          lblCases.Text = "No Cases Found";
  }

  protected void gvSubmittedCases_RowEditing(object sender, GridViewEditEventArgs e)
  {
      gvSubmittedCases.EditIndex = e.NewEditIndex;
      CaseView();
  }



protected void gvSubmittedCases_RowCancelingEdit(object sender,GridViewCancelEditEventArgs e)
   {
       gvSubmittedCases.EditIndex = -1;
       CaseView();

   }




Also, there is one field FraudType that i want to be dropDown when the user clicks on edit.

I hope i have cleared my question.
You can ask if anything needs to get cleared.

Note:

I am using Stored Procedures to Update the database, which is in SQL


Thanks

What I have tried:

I have searched web, but there is no proper solution for BoundField + Stored Procedures

解决方案


这篇关于使用boundfield更新gridview的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-16 09:40