1

グリッドビューを取得しましたが、更新を示すハイパーリンク列があります。そのページをクリックすると、別のページにリダイレクトされ、特定の行の値が別のグリッドビューに表示されます。そこでユーザーは1列を編集して更新する必要があり、その後、グリッドビューの外に送信または受け入れのボタンがあり、クリックするとメールが生成され、更新されたグリッド値を取得して他のユーザーに送信し、ページは前のページにリダイレクトされます。

グリッドビューのaspxコード

<asp:GridView ID="GridView1" runat="server" AllowSorting="True" 
                     AutoGenerateColumns="false" BackColor="White" BorderColor="#0061C1" 
                     BorderStyle="None" CaptionAlign="Bottom" EmptyDataText="No Records Found" 
                     Font-Names="Verdana" Font-Size="X-Small" ForeColor="#0061C1" Height="70px" 
                     ShowFooter="True" ShowHeaderWhenEmpty="True" OnRowCommand="GridView1_RowCommand" 
                     OnRowDataBound="GridView1_RowDataBound" OnRowEditing="GridView1_RowEditing"
                     onselectedindexchanged="GridView1_SelectedIndexChanged" OnRowUpdating="GridView1_RowUpdating"
                     Width="796px">
                     <Columns>
                         <asp:BoundField DataField="LeaveID" Visible="false">
                         <FooterStyle BackColor="#0061C1" />
                         <HeaderStyle BackColor="#0061C1" ForeColor="White" HorizontalAlign="Center" 
                             VerticalAlign="Middle" />
                         <ItemStyle HorizontalAlign="Center" VerticalAlign="Middle" Width="10px" />
                         </asp:BoundField>
                         <asp:TemplateField HeaderText="Applied By">
                         <ItemTemplate>
                         <asp:Label 
                            ID="LoggedInUser" runat="server" Font-Names="Verdana" Font-Size="X-Small" 
                            Height="24px" Text='<%# Eval("LoggedInUser")%>' Width="100px"></asp:Label>
                    </ItemTemplate>
                    <FooterStyle BackColor="#0061C1" />
                    <HeaderStyle BackColor="#0061C1" ForeColor="White"></HeaderStyle>
                    <ItemStyle HorizontalAlign="Center" VerticalAlign="Middle"></ItemStyle>
                    </asp:TemplateField>
                    <asp:TemplateField HeaderText="Begin Date">
                    <ItemTemplate>
                    <asp:Label 
                            ID="BeginDate" runat="server" DataFormatString="{0:dd/MM/yyyy}" 
                            Font-Names="Verdana" Text='<%# Eval("BeginDate","{0:dd/MM/yyyy}")%>' Font-Size="X-Small" Height="20px" 
                             Width="100px"></asp:Label>
                    </ItemTemplate>
                    <FooterStyle BackColor="#0061C1" />
                    <HeaderStyle BackColor="#0061C1" ForeColor="White"></HeaderStyle>
                    <ItemStyle HorizontalAlign="Center" VerticalAlign="Middle"></ItemStyle>
                    </asp:TemplateField>
                    <asp:TemplateField HeaderText="End Date">
                    <ItemTemplate>
                    <asp:Label 
                            ID="EndDate" runat="server" Font-Names="Verdana" Font-Size="X-Small" 
                            Height="20px" Text='<%# Eval("EndDate","{0:dd/MM/yyyy}")%>'  Width="100px"></asp:Label>
                    </ItemTemplate>
                    <FooterStyle BackColor="#0061C1" />
                    <HeaderStyle BackColor="#0061C1" ForeColor="White"></HeaderStyle>
                    <ItemStyle HorizontalAlign="Center" VerticalAlign="Middle"></ItemStyle>
                    </asp:TemplateField>
                    <asp:TemplateField HeaderText="Num of Days">
                    <ItemTemplate>
                    <asp:Label 
                            ID="NumofDays" runat="server" Font-Names="Verdana" Font-Size="X-Small" 
                            Height="20px" Text='<%# Eval("NumofDays")%>' Width="100px"></asp:Label>
                    </ItemTemplate>
                    <FooterStyle BackColor="#0061C1" />
                    <HeaderStyle BackColor="#0061C1" ForeColor="White"></HeaderStyle>
                    <ItemStyle HorizontalAlign="Center" VerticalAlign="Middle"></ItemStyle>
                    </asp:TemplateField>
                    <asp:TemplateField HeaderText="Type of Leave ">
                    <ItemTemplate>
                    <asp:Label 
                            ID="LeaveType" runat="server" Font-Names="Verdana" Font-Size="X-Small" 
                            Height="20px" Text='<%# Eval("TypeofLeave")%>'  Width="100px"></asp:Label>
                    </ItemTemplate>
                    <FooterStyle BackColor="#0061C1" />
                    <HeaderStyle BackColor="#0061C1" ForeColor="White"></HeaderStyle>
                    <ItemStyle HorizontalAlign="Center" VerticalAlign="Middle"></ItemStyle>
                    </asp:TemplateField>
                    <asp:TemplateField HeaderText="Status">
                    <ItemTemplate>
                    <asp:Label 
                            ID="Status" runat="server" Font-Names="Verdana" Font-Size="X-Small" 
                            ForeColor="Black" Height="20px" Text='<%# Eval("Status")%>'  Width="100px"></asp:Label>
                    </ItemTemplate>
                    <FooterStyle BackColor="#0061C1" />
                    <HeaderStyle BackColor="#0061C1" ForeColor="White"></HeaderStyle>
                    <ItemStyle HorizontalAlign="Center" VerticalAlign="Middle"></ItemStyle>
                    </asp:TemplateField>
                        <asp:TemplateField  HeaderText="Reason for Reject">
                        <ItemTemplate>
                        <asp:Label ID="RejectReason" 
                            runat="server" Font-Names="Verdana" Font-Size="X-Small" ForeColor="Black" 
                            Height="20px" Text='<%# Eval("RejectReason")%>' Enabled="true" Visible="true" Width="100px"></asp:Label>
                    </ItemTemplate>
                    <EditItemTemplate>
                    <asp:TextBox ID="TxtRejectReason" 
                            runat="server" Font-Names="Verdana" Font-Size="X-Small" ForeColor="Black" 
                            Height="20px" Text='<%# Eval("RejectReason")%>' Enabled="true" Visible="true" Width="100px"></asp:TextBox>
                    </EditItemTemplate>
                    <FooterStyle BackColor="#0061C1" />
                    <HeaderStyle BackColor="#0061C1" ForeColor="White"></HeaderStyle>
                    <ItemStyle HorizontalAlign="Center" VerticalAlign="Middle"></ItemStyle>
                    </asp:TemplateField>
                         <asp:BoundField DataField="LogdInUser" Visible="false" >
                         <FooterStyle BackColor="#0061C1" />
                         <HeaderStyle BackColor="#0061C1" ForeColor="White" HorizontalAlign="Center" 
                             VerticalAlign="Middle" />
                         <ItemStyle HorizontalAlign="Center" VerticalAlign="Middle" Width="100px" />
                         </asp:BoundField>
                         <asp:BoundField DataField="Manager" Visible="false" >
                         <FooterStyle BackColor="#0061C1" />
                         <HeaderStyle BackColor="#0061C1" ForeColor="White" HorizontalAlign="Center" 
                             VerticalAlign="Middle" />
                         <ItemStyle HorizontalAlign="Center" VerticalAlign="Middle" Width="100px" />
                         </asp:BoundField>
                         <asp:CommandField ShowEditButton="true"  ButtonType="Button"  EditText="Edit">
                <ControlStyle Width="50" />
            </asp:CommandField>
                     </Columns>
                 </asp:GridView>

RejectReason 列を編集する必要があります。

csページ

protected void Page_Load(object sender, EventArgs e)
    {
        MTMSDTO objc = new MTMSDTO();
        if (!IsPostBack)
        {
            int LeaveID = 0;
            int.TryParse(Request.QueryString["LeaveID"], out LeaveID);
            objc.LeaveID = LeaveID;
            objc.RejectReason = TxtRejectReason.Text;
            DataSet lapp = obj.GetLeaveApproved(objc);
            DataView LApp = new DataView();
            LApp.Table = lapp.Tables[0];
            GridView1.DataSource = LApp;
            GridView1.DataBind();

        }
    }

    protected void GridView1_RowEditing(object sender, GridViewEditEventArgs e)
    {
        GridView1.EditIndex = e.NewEditIndex;
        GridView1.DataBind();
    }

    protected void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e)
    {
        int LeaveID = Convert.ToInt32(GridView1.DataKeys[e.RowIndex].Value.ToString());

        TextBox TxtRejectReason = (TextBox)GridView1.Rows[e.RowIndex].FindControl("TxtRejectReason");

        GridView1.EditIndex = -1;
        GridView1.DataBind();
    }

グリッドビューの編集ボタンをクリックすると、レコードが表示されません

私を助けてください

4

2 に答える 2

1

グリッドビュー編集時にコードを使用し、

protected void GridView1_RowEditing(object sender, GridViewEditEventArgs e)
{
    GridView gridView1= (GridView)sender;
   // Change the row state
    gridView1.Rows[e.NewEditIndex].RowState = DataControlRowState.Edit;

}

アップデート用(サンプルコードです)

 protected void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e)
 {
      GridView gv = (GridView)sender;
      GridViewRow gvr = (GridViewRow)gv.Rows[e.RowIndex];
      TextBox TxtRejectReason= (TextBox)gvr.FindControl("TxtRejectReason");
      string s = TxtRejectReason.Text;
      GridView.EditIndex = -1;
      GridView.DataBind();
 }
于 2013-07-26T06:53:50.440 に答える