<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False"
Width="100%" AllowPaging="True" DataKeyNames="VoucherNo"
OnPageIndexChanging="GridView1_PageIndexChanging"
OnRowEditing="GridView1_RowEditing" OnRowUpdating="GridView1_RowUpdating"
OnRowCancelingEdit="GridView1_RowCancelingEdit" OnRowDeleting="GridView1_RowDeleting" OnRowDataBound="GridView1_RowDataBound" PageSize="7" OnRowCommand="GridView1_RowCommand">
<Columns>
<asp:CommandField ShowEditButton="True" HeaderText="Edit">
<HeaderStyle BackColor="#CCCCCC" BorderColor="#999999" BorderStyle="Solid" BorderWidth="1px" HorizontalAlign="Center" />
<ItemStyle BorderColor="#999999" BorderStyle="Solid" BorderWidth="1px" />
</asp:CommandField>
<asp:ButtonField HeaderText="View" Text="View" CommandName="VoucherNo" SortExpression="VoucherNo">
<HeaderStyle BackColor="#CCCCCC" BorderColor="#999999" BorderStyle="Solid" BorderWidth="1px" HorizontalAlign="Center" Width="40px" />
<ItemStyle BorderColor="#999999" BorderStyle="Solid" BorderWidth="1px" />
</asp:ButtonField>
<asp:BoundField DataField="EntryDate" HeaderText="Date" ReadOnly="True" DataFormatString="{0:d}">
<HeaderStyle BackColor="#CCCCCC" BorderColor="#999999" BorderStyle="Solid" BorderWidth="1px" HorizontalAlign="Center" />
<ItemStyle BorderColor="#999999" BorderStyle="Solid" BorderWidth="1px" Width="120px" />
</asp:BoundField>
<asp:BoundField DataField="AccountName" HeaderText="Account Name" DataFormatString="{0:0.00}" ReadOnly="True">
<HeaderStyle BackColor="#CCCCCC" BorderColor="#999999" BorderStyle="Solid" BorderWidth="1px" CssClass="HeaderStylCenter" />
<ItemStyle BorderColor="#999999" BorderStyle="Solid" BorderWidth="1px" HorizontalAlign="Left" />
</asp:BoundField>
<%-- <asp:BoundField DataField="ToAcc" HeaderText="To Account" ReadOnly="True">
<HeaderStyle BackColor="#CCCCCC" BorderColor="#999999" BorderStyle="Solid" BorderWidth="1px" CssClass="HeaderStylCenter" />
<ItemStyle BorderColor="#999999" BorderStyle="Solid" BorderWidth="1px" HorizontalAlign="Right" />
</asp:BoundField>--%>
<asp:BoundField DataField="DAmount" HeaderText="Debit" ReadOnly="True" DataFormatString="{0:0.00}">
<HeaderStyle BackColor="#CCCCCC" BorderColor="#999999" BorderStyle="Solid" BorderWidth="1px" CssClass="HeaderStylRight" Width="100px" />
<ItemStyle BorderColor="#999999" BorderStyle="Solid" BorderWidth="1px" CssClass="HeaderStylRight" />
</asp:BoundField>
<asp:BoundField DataField="CAmount" HeaderText="Credit" ReadOnly="True" DataFormatString="{0:0.00}">
<HeaderStyle BackColor="#CCCCCC" BorderColor="#999999" BorderStyle="Solid" BorderWidth="1px" CssClass="HeaderStylRight" Width="100px" />
<ItemStyle BorderColor="#999999" BorderStyle="Solid" BorderWidth="1px" CssClass="HeaderStylRight" />
</asp:BoundField>
<asp:BoundField DataField="Balance" HeaderText="Balance" ReadOnly="True" DataFormatString="{0:0.00}">
<HeaderStyle BackColor="#CCCCCC" BorderColor="#999999" BorderStyle="Solid" BorderWidth="1px" CssClass="HeaderStylRight" Width="100px" />
<ItemStyle BorderColor="#999999" BorderStyle="Solid" BorderWidth="1px" CssClass="HeaderStylRight" />
</asp:BoundField>
<asp:BoundField DataField="Descrp" HeaderText="Comments">
<HeaderStyle BackColor="#CCCCCC" BorderColor="#999999" BorderStyle="Solid" BorderWidth="1px" HorizontalAlign="Center" />
<ItemStyle BorderColor="#999999" BorderStyle="Solid" BorderWidth="1px" />
</asp:BoundField>
</Columns>
</asp:GridView>
C# code:
protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
{
if (e.CommandName == "VoucherNo")
{
string nov = ((GridView) e.CommandSource).DataKeys[1].Value.ToString();
Session["nov"] = nov;
Response.Write("<script> window.open('ViewJournalDetailsUI.aspx','_blank')</script>");
}
}
protected void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e)
{
try
{
GridViewRow rowIndex = GridView1.Rows[e.RowIndex];
string vno = GridView1.DataKeys[e.RowIndex].Values["VoucherNo"].ToString();
string comment = ((TextBox)(rowIndex.Cells[7].Controls[0])).Text;
comment = comment.Replace("'", "''");
if (UpdateData(vno, comment))
{
Show("Updated");
GridView1.EditIndex = -1;
}
else
{
Show("Error Updating");
}
FillGrid();
}
catch (Exception ex)
{
Show(ex.Message.ToString());
}
}
Width="100%" AllowPaging="True" DataKeyNames="VoucherNo"
OnPageIndexChanging="GridView1_PageIndexChanging"
OnRowEditing="GridView1_RowEditing" OnRowUpdating="GridView1_RowUpdating"
OnRowCancelingEdit="GridView1_RowCancelingEdit" OnRowDeleting="GridView1_RowDeleting" OnRowDataBound="GridView1_RowDataBound" PageSize="7" OnRowCommand="GridView1_RowCommand">
<Columns>
<asp:CommandField ShowEditButton="True" HeaderText="Edit">
<HeaderStyle BackColor="#CCCCCC" BorderColor="#999999" BorderStyle="Solid" BorderWidth="1px" HorizontalAlign="Center" />
<ItemStyle BorderColor="#999999" BorderStyle="Solid" BorderWidth="1px" />
</asp:CommandField>
<asp:ButtonField HeaderText="View" Text="View" CommandName="VoucherNo" SortExpression="VoucherNo">
<HeaderStyle BackColor="#CCCCCC" BorderColor="#999999" BorderStyle="Solid" BorderWidth="1px" HorizontalAlign="Center" Width="40px" />
<ItemStyle BorderColor="#999999" BorderStyle="Solid" BorderWidth="1px" />
</asp:ButtonField>
<asp:BoundField DataField="EntryDate" HeaderText="Date" ReadOnly="True" DataFormatString="{0:d}">
<HeaderStyle BackColor="#CCCCCC" BorderColor="#999999" BorderStyle="Solid" BorderWidth="1px" HorizontalAlign="Center" />
<ItemStyle BorderColor="#999999" BorderStyle="Solid" BorderWidth="1px" Width="120px" />
</asp:BoundField>
<asp:BoundField DataField="AccountName" HeaderText="Account Name" DataFormatString="{0:0.00}" ReadOnly="True">
<HeaderStyle BackColor="#CCCCCC" BorderColor="#999999" BorderStyle="Solid" BorderWidth="1px" CssClass="HeaderStylCenter" />
<ItemStyle BorderColor="#999999" BorderStyle="Solid" BorderWidth="1px" HorizontalAlign="Left" />
</asp:BoundField>
<%-- <asp:BoundField DataField="ToAcc" HeaderText="To Account" ReadOnly="True">
<HeaderStyle BackColor="#CCCCCC" BorderColor="#999999" BorderStyle="Solid" BorderWidth="1px" CssClass="HeaderStylCenter" />
<ItemStyle BorderColor="#999999" BorderStyle="Solid" BorderWidth="1px" HorizontalAlign="Right" />
</asp:BoundField>--%>
<asp:BoundField DataField="DAmount" HeaderText="Debit" ReadOnly="True" DataFormatString="{0:0.00}">
<HeaderStyle BackColor="#CCCCCC" BorderColor="#999999" BorderStyle="Solid" BorderWidth="1px" CssClass="HeaderStylRight" Width="100px" />
<ItemStyle BorderColor="#999999" BorderStyle="Solid" BorderWidth="1px" CssClass="HeaderStylRight" />
</asp:BoundField>
<asp:BoundField DataField="CAmount" HeaderText="Credit" ReadOnly="True" DataFormatString="{0:0.00}">
<HeaderStyle BackColor="#CCCCCC" BorderColor="#999999" BorderStyle="Solid" BorderWidth="1px" CssClass="HeaderStylRight" Width="100px" />
<ItemStyle BorderColor="#999999" BorderStyle="Solid" BorderWidth="1px" CssClass="HeaderStylRight" />
</asp:BoundField>
<asp:BoundField DataField="Balance" HeaderText="Balance" ReadOnly="True" DataFormatString="{0:0.00}">
<HeaderStyle BackColor="#CCCCCC" BorderColor="#999999" BorderStyle="Solid" BorderWidth="1px" CssClass="HeaderStylRight" Width="100px" />
<ItemStyle BorderColor="#999999" BorderStyle="Solid" BorderWidth="1px" CssClass="HeaderStylRight" />
</asp:BoundField>
<asp:BoundField DataField="Descrp" HeaderText="Comments">
<HeaderStyle BackColor="#CCCCCC" BorderColor="#999999" BorderStyle="Solid" BorderWidth="1px" HorizontalAlign="Center" />
<ItemStyle BorderColor="#999999" BorderStyle="Solid" BorderWidth="1px" />
</asp:BoundField>
</Columns>
</asp:GridView>
C# code:
protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
{
if (e.CommandName == "VoucherNo")
{
string nov = ((GridView) e.CommandSource).DataKeys[1].Value.ToString();
Session["nov"] = nov;
Response.Write("<script> window.open('ViewJournalDetailsUI.aspx','_blank')</script>");
}
}
protected void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e)
{
try
{
GridViewRow rowIndex = GridView1.Rows[e.RowIndex];
string vno = GridView1.DataKeys[e.RowIndex].Values["VoucherNo"].ToString();
string comment = ((TextBox)(rowIndex.Cells[7].Controls[0])).Text;
comment = comment.Replace("'", "''");
if (UpdateData(vno, comment))
{
Show("Updated");
GridView1.EditIndex = -1;
}
else
{
Show("Error Updating");
}
FillGrid();
}
catch (Exception ex)
{
Show(ex.Message.ToString());
}
}
কোন মন্তব্য নেই:
একটি মন্তব্য পোস্ট করুন