ManageCategory.aspx(Page)
<div id="divHeader" class="headercontent" runat="server">
Manage Product Categories
<div id="divContentInnerContent" class="contentinnercontent" runat="server">
<asp:Button ID="btnCancel" runat="server" Text="Cancel" CssClass="ui-widget-header" />
<asp:Button ID="btnAdd" runat="server" Text="Add Catgory" CssClass="ui-widget-header" />
|
<asp:UpdatePanel ID="updAreaAdmin" UpdateMode="Conditional" runat="server">
<contenttemplate>
<asp:GridView ID="gvCategory" CssClass="tablesorter" runat="server" AutoGenerateColumns="False"
GridLines="Horizontal" EmptyDataText="No Category entries available." CellPadding="6"
EnableViewState="true" DataKeyNames="CategoryID" Width="99%">
<columns> <asp:TemplateField HeaderStyle-CssClass="CellHidden" ItemStyle-CssClass="CellHidden">
<itemtemplate>
<asp:Label ID="lblCategoryID" Text='<%# Bind("CategoryID") %>' runat="server">
<footertemplate>
<asp:Label ID="lblCategoryId" Text='0' runat="server">
<footerstyle cssclass="CellHidden">
<itemstyle width="0px">
<asp:TemplateField HeaderText="Category Name">
<itemstyle width="30%" horizontalalign="Left" wrap="false">
<footerstyle width="30%" horizontalalign="Left" wrap="false">
<itemtemplate>
<asp:Label ID="lblCategoryName" runat="server" Text='<%#DataBinder.Eval(Container.DataItem, "Category_Name") %>' />
<edititemtemplate>
<asp:TextBox ID="txtCategoryName" runat="server" Width="250px" Text='<%#DataBinder.Eval(Container.DataItem, "Category_Name") %>' />
<footertemplate>
<asp:TextBox ID="txtCategoryName" runat="server" Width="250px" />
<asp:TemplateField HeaderText="Category Description">
<itemstyle width="30%" horizontalalign="Left" wrap="false">
<footerstyle width="30%" horizontalalign="Left" wrap="false">
<itemtemplate>
<asp:Label ID="lblCategoryDesc" runat="server" Text='<%#DataBinder.Eval(Container.DataItem, "Category_Description") %>' />
<edititemtemplate>
<asp:TextBox ID="txtCategoryDesc" runat="server" Width="250px" Text='<%#DataBinder.Eval(Container.DataItem, "Category_Description") %>' />
<footertemplate>
<asp:TextBox ID="txtCategoryDesc" runat="server" Width="250px" />
<asp:TemplateField HeaderText="Category Image">
<itemstyle width="20%" horizontalalign="Left" wrap="false">
<footerstyle width="20%" horizontalalign="Left" wrap="false">
<itemtemplate>
<asp:Image ID="img1" runat="server" ImageUrl='<%# Eval("Category_ImageFilePath") %>'
Width="25px" Height="25px" />
<edititemtemplate>
<%-- <asp:TextBox ID="txtCategoryImage" runat="server" Width="250px" Text='<%#DataBinder.Eval(Container.DataItem, "Category_ImageFilePath") %>' />--%>
<asp:FileUpload ID="flupImage" runat="server" Width="175px" />
<asp:Image ID="imgPic" runat="server" Width="25px" Height="25px" ImageUrl='<%#Eval("Category_ImageFilePath")%>' />
<footertemplate>
<asp:Label ID="txtCategoryImage" runat="server" />
<asp:TemplateField HeaderText="Is Active">
<itemstyle width="15%" horizontalalign="Left" wrap="false">
<footerstyle width="15%" horizontalalign="Left" wrap="false">
<itemtemplate>
<asp:Label ID="lblIsActive" runat="server" Text='<%#DataBinder.Eval(Container.DataItem, "Category_IsActive") %>' />
<edititemtemplate>
<asp:DropDownList ID="ddlEditIsActive" runat="server">
<asp:ListItem Value="1" Text="True" Selected="True" />
<asp:ListItem Value="0" Text="False" />
<footertemplate>
<asp:DropDownList ID="ddlIsActive" runat="server">
<asp:ListItem Value="1" Text="True" Selected="True" />
<asp:ListItem Value="0" Text="False" />
<asp:CommandField EditText="<img src='../../Common/Images/row_edit_20x20.png' border=0 title='Edit'>"
ShowEditButton="true" ButtonType="Link" ShowCancelButton="false" UpdateText="<img src='../../Common/Images/row_save_20x20.png' border=0 title='Save'>">
<asp:TemplateField>
<itemstyle width="10%">
<footerstyle width="10%">
<itemtemplate>
<asp:LinkButton Text="<img src='../../Common/Images/row_delete_20x20.png' style='border:0px' />"
runat="server" ID="imgButtonDelete" ToolTip="Delete" CausesValidation="false"
CommandName="Delete">
<footertemplate>
<asp:LinkButton Text="<img src='../../Common/Images/row_save_20x20.png' style='border:0px' />"
runat="server" ID="lnkSave" CommandName="Save">
<triggers> <asp:AsyncPostBackTrigger ControlID="btnAdd" />
<asp:AsyncPostBackTrigger ControlID="btnCancel" />
and
VB Code-:
Imports FindurBiz.Utilities
Imports FindurBiz.Business.CategorySubCategory
Partial Public Class ManageCategory
Inherits FindurBizBasePage
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
If Not Page.IsPostBack Then
BindCategory()
End If
End Sub
Private Sub BindCategory()
Dim dtCategory As DataTable
Try
dtCategory = AdminCategoryGet()
gvCategory.DataSource = dtCategory
gvCategory.DataBind()
Catch ex As Exception
End Try
End Sub
Private Sub gvCategory_RowCommand(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewCommandEventArgs) Handles gvCategory.RowCommand
Try
If e.CommandName.Equals("Save") Then
Dim iCategoryID As Integer
Dim strCategoryName As String = String.Empty
Dim strCategoryDesc As String = String.Empty
Dim strCategoryImage As String = String.Empty
Dim iIsActive As Integer
iCategoryID = CType(gvCategory.FooterRow.FindControl("lblCategoryID"), Label).Text
strCategoryName = CType(gvCategory.FooterRow.FindControl("txtCategoryName"), TextBox).Text
strCategoryDesc = CType(gvCategory.FooterRow.FindControl("txtCategoryDesc"), TextBox).Text
'strCategoryImage = CType(gvCategory.FooterRow.FindControl("txtCategoryImage"), TextBox).Text
strCategoryImage = CType(gvCategory.FooterRow.FindControl("flupImage"), FileUpload).FileName
iIsActive = CType(gvCategory.FooterRow.FindControl("ddlIsActive"), DropDownList).SelectedItem.Value
CategorySave(iCategoryID, strCategoryName, strCategoryDesc, strCategoryImage, iIsActive)
Else
Dim strImageUpload As FileUpload = CType(gvCategory.FooterRow.FindControl("flupImage"), FileUpload)
Dim FileName As String = String.Empty
Dim strCategoryImage1 As String = String.Empty
If (strImageUpload IsNot Nothing) Then
If (strImageUpload.HasFile) Then
Dim strPath As String = Server.MapPath("../Common/CategoryImage/")
strImageUpload.SaveAs(strPath + strImageUpload.FileName)
FileName = strImageUpload.FileName
FileName = "../Common/Images/" + strImageUpload.FileName
strCategoryImage1 = "../Common/CategoryImage/" + strImageUpload.FileName
CType(gvCategory.FooterRow.FindControl("imgPic"), Image).ImageUrl = strCategoryImage1
End If
End If
End If
'ElseIf
Catch ex As Exception
Throw New ApplicationException("gvArea_RowCommand", ex)
End Try
End Sub
Private Sub gvCategory_RowDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles gvCategory.RowDataBound
If e.Row.RowType = DataControlRowType.DataRow Then
'Confirm removals
Dim lb As LinkButton = CType(e.Row.FindControl("imgButtonDelete"), LinkButton)
lb.OnClientClick = "return confirm('Are you sure you want to remove the Category Type?');"
End If
End Sub
Private Sub gvCategory_RowDeleting(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewDeleteEventArgs) Handles gvCategory.RowDeleting
Dim dsResult As DataSet
Dim CategoryID As Integer
Try
CategoryID = CType(gvCategory.Rows(e.RowIndex).FindControl("lblCategoryID"), Label).Text
dsResult = AdminCategoryDelete(CategoryID)
If dsResult.Tables(0).Rows.Count > 0 Then
If dsResult.Tables(0).Rows(0)("Result") <> "Success" Then
Me.ShowMessage(Common.MessageStatus.Err, dsResult.Tables(0).Rows(0)("Result").ToString(), lblMessage.ClientID, True)
Exit Sub
Else
Me.ShowMessage(Common.MessageStatus.Save, "Category Type Deleted.", lblMessage.ClientID, True)
BindCategory()
End If
End If
Catch ex As Exception
Throw New ApplicationException("AreaAdmin.aspx-Delete", ex)
End Try
End Sub
Private Sub gvCategory_RowEditing(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewEditEventArgs) Handles gvCategory.RowEditing
gvCategory.EditIndex = e.NewEditIndex
SetupFooter(False)
gvCategory.Rows(e.NewEditIndex).FindControl("imgButtonDelete").Visible = False 'Hide on edit
End Sub
Private Sub gvCategory_RowUpdating(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewUpdateEventArgs) Handles gvCategory.RowUpdating
Dim iCategoryID As Integer
Dim strCategoryName As String = String.Empty
Dim strCategoryDesc As String = String.Empty
Dim strCategoryImage As String = String.Empty
Dim iIsActive As Integer
Dim FileName As String = String.Empty
Dim strImageUpload As FileUpload = CType(gvCategory.Rows(e.RowIndex).FindControl("flupImage"), FileUpload)
If (strImageUpload.HasFile) Then
Dim strPath As String = Server.MapPath("../Common/CategoryImage/")
strImageUpload.SaveAs(strPath + strImageUpload.FileName)
FileName = strImageUpload.FileName
FileName = "../Common/Images/" + strImageUpload.FileName
strCategoryImage = "../Common/CategoryImage/" + strImageUpload.FileName
Else
strCategoryImage = CType(gvCategory.Rows(e.RowIndex).FindControl("imgPic"), Image).ImageUrl
End If
iCategoryID = CType(gvCategory.Rows(e.RowIndex).FindControl("lblCategoryID"), Label).Text
strCategoryName = CType(gvCategory.Rows(e.RowIndex).FindControl("txtCategoryName"), TextBox).Text
strCategoryDesc = CType(gvCategory.Rows(e.RowIndex).FindControl("txtCategoryDesc"), TextBox).Text
'strCategoryImage = CType(gvCategory.Rows(e.RowIndex).FindControl("imgPic"), Image).ImageUrl
Dim strCategoryImage1 As String = strCategoryImage.Substring(strCategoryImage.LastIndexOf("/") + 1)
iIsActive = CType(gvCategory.Rows(e.RowIndex).FindControl("ddlEditIsActive"), DropDownList).SelectedItem.Value
CategorySave(iCategoryID, strCategoryName, strCategoryDesc, strCategoryImage1, iIsActive)
gvCategory.EditIndex = -1
BindCategory()
End Sub
Private Sub CategorySave(ByVal iCategoryID As Integer, ByVal strCategoryName As String, ByVal strCategoryDesc As String, ByVal strCategoryImage As String, ByVal iIsActive As Integer)
Try
If Not String.IsNullOrEmpty(strCategoryName) Then
If CheckExistingCategory(strCategoryName) Then
AdminCategoryUpdate(iCategoryID, strCategoryName, strCategoryDesc, strCategoryImage, iIsActive)
Me.ShowMessage(Common.MessageStatus.Information, "Category Information Saved.", lblMessage.ClientID, True)
SetupFooter(False)
Else
Me.ShowMessage(Common.MessageStatus.Information, "Category Name already being used.", lblMessage.ClientID, True)
End If
Else
If gvCategory.Rows.Count <> 0 Then
Me.ShowMessage(Common.MessageStatus.Information, "Category Name is required.", lblMessage.ClientID, True)
Else
AdminCategoryUpdate(iCategoryID, strCategoryName, strCategoryDesc, strCategoryImage, iIsActive)
End If
End If
Catch ex As Exception
End Try
End Sub
Private Sub SetupFooter(ByVal bShowFooter As Boolean)
gvCategory.ShowFooter = bShowFooter
BindCategory()
End Sub
Private Sub btnAdd_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnAdd.Click
If gvCategory.Rows.Count = 0 Then
CategorySave(0, "", "", "", True)
gvCategory.EditIndex = 0
SetupFooter(False)
Else
gvCategory.EditIndex = -1
SetupFooter(True)
End If
End Sub
End Class
when edit button click in gridview after that datas are shown in gridview with images if after that otehr images are upload then image change is not working because below code is not entered if condition.....
Private Sub gvCategory_RowUpdating(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewUpdateEventArgs) Handles gvCategory.RowUpdating
Dim iCategoryID As Integer
Dim strCategoryName As String = String.Empty
Dim strCategoryDesc As String = String.Empty
Dim strCategoryImage As String = String.Empty
Dim iIsActive As Integer
Dim FileName As String = String.Empty
Dim strImageUpload As FileUpload = CType(gvCategory.Rows(e.RowIndex).FindControl("flupImage"), FileUpload)
If (strImageUpload.HasFile) Then
Dim strPath As String = Server.MapPath("../Common/CategoryImage/")
strImageUpload.SaveAs(strPath + strImageUpload.FileName)
FileName = strImageUpload.FileName
FileName = "../Common/Images/" + strImageUpload.FileName
strCategoryImage = "../Common/CategoryImage/" + strImageUpload.FileName
Else
strCategoryImage = CType(gvCategory.Rows(e.RowIndex).FindControl("imgPic"), Image).ImageUrl
End If
iCategoryID = CType(gvCategory.Rows(e.RowIndex).FindControl("lblCategoryID"), Label).Text
strCategoryName = CType(gvCategory.Rows(e.RowIndex).FindControl("txtCategoryName"), TextBox).Text
strCategoryDesc = CType(gvCategory.Rows(e.RowIndex).FindControl("txtCategoryDesc"), TextBox).Text
Dim strCategoryImage1 As String = strCategoryImage.Substring(strCategoryImage.LastIndexOf("/") + 1)
iIsActive = CType(gvCategory.Rows(e.RowIndex).FindControl("ddlEditIsActive"), DropDownList).SelectedItem.Value
CategorySave(iCategoryID, strCategoryName, strCategoryDesc, strCategoryImage1, iIsActive)
gvCategory.EditIndex = -1
BindCategory()
End Sub
so, please help me................