如何从网格视图更改图像并更新vb中的图像? [英] how to change image from grid view and update image in vb?

查看:92
本文介绍了如何从网格视图更改图像并更新vb中的图像?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

ManageCategory.aspx(页)



ManageCategory.aspx(Page)






< div id =divHeaderclass =headercontentrunat =server>

管理产品类别


<div id="divHeader" class="headercontent" runat="server">
Manage Product Categories



< div id =divContentInnerContentclass =contentinnercontentrunat =server>


<div id="divContentInnerContent" class="contentinnercontent" runat="server">





< asp:Button ID =btnCancelrunat =serverText =CancelCssClass =ui-widget-header/> 

& lt; asp:Button ID =btnAddrunat =serverText =Add CatgoryCssClass =ui-widget-header/>





<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 =updAreaAdminUpdateMode =条件runat =server>

< contenttemplate>

< asp:GridView ID =gvCategoryCssClass =tablesorterrunat =serverAutoGenerateColumns =False

GridLines =Horizo​​ntalEmptyDataText =没有可用的类别条目。 CellPadding =6

EnableViewState =trueDataKeyNames =CategoryIDWidth =99%>

< columns> < asp:TemplateField HeaderStyle-CssClass =CellHiddenItemStyle-CssClass =CellHidden>

< itemtemplate>

< asp:Label ID =lblCategoryID Text ='<%#Bind(CategoryID)%>'runat =server>



< footertemplate>

< asp:Label ID =lblCategoryIdText ='0'runat =server>



< footerstyle cssclass =CellHidden> ;

< itemstyle width =0px>



< asp:TemplateField HeaderText =类别名称>

< itemstyle width =30%horizo​​ntalalign =Leftwrap =false>

< footerstyle width =30%horizo​​ntalalign =leftwrap =false>

< itemtemplate>

< asp:Label ID =lblCategoryName runat =serverText ='<%#DataBinder.Eval(Container.DataItem,Category_Name)%>'/>



< edititemtemplate>

< asp:TextBox ID =txtCategoryNamerunat =serverWidth =250pxText ='<%#DataBinder.Eval(Container.DataItem, Category_Name)%>'/>



< footertemplate>

< asp:TextBox ID =txtCategoryNamerunat =serverWidth =250px/>





< asp:TemplateField HeaderText =类别描述>

< itemstyle width =30%horizo​​ntalalign =Leftwrap =false>

< footerstyle width =30%horizo​​ntalalign =Left wrap =false>

< itemtemplate>

< asp:Label ID =lblCategoryDe​​scrunat =serverText ='<%#DataBinder.Eval(Container.DataItem,Category_Description)%>'/>



< edititemtemplate>

< asp:TextBox ID =txtCategoryDe​​scrunat =serverWidth =250pxText ='<%#DataBinder.Eval( Container.DataItem,Category_Description)%>'/>



< footertemplate>

< asp:TextBox ID = txtCategoryDe​​scrunat =serverWidth =250px/>







< asp:TemplateField HeaderText =Category Image>

< itemstyle width =20%horizo​​ntalalign =Leftwrap =false>

< footerstyle width =20%horizo​​ntalalign =leftwrap =false>

< itemtemplate>

< asp:Image ID =img1 runat =serverImageUrl ='<%#Eval(Category_ImageFilePath)%>'

Width =25pxHeight =25px/>



< edititemtemplate>

<% - < asp:TextBox ID =txtCat egoryImagerunat =serverWidth =250pxText ='<%#DataBinder.Eval(Container.DataItem,Category_ImageFilePath)%>'/> - %>

< asp:FileUpload ID =flupImagerunat =serverWidth =175px/>

< asp:Image ID =imgPicrunat =serverWidth = 25pxHeight =25pxImageUrl ='<%#Eval(Category_ImageFilePath)%>'/>



< footertemplate>

< asp:Label ID =txtCategoryImagerunat =server/>







< asp:TemplateField Head erText =有效>

< itemstyle width =15%horizo​​ntalalign =Leftwrap =false>

< footerstyle width = 15%horizo​​ntalalign =Leftwrap =false>

< itemtemplate>

< asp:Label ID =lblIsActiverunat =server Text ='<%#DataBinder.Eval(Container.DataItem,Category_IsActive)%>'/>



< edititemtemplate>

< asp:DropDownList ID =ddlEditIsActiverunat =server>

< asp:ListItem Value =1Text =TrueSelected =Tr ue/>

< asp:ListItem Value =0Text =False/>





< footertemplate>

< asp:DropDownList ID =ddlIsActiverunat =server>

< asp:ListItem Value = 1Text =TrueSelected =True/>

< asp:ListItem Value =0Text =False/>

< br $> b $ b



< asp:CommandField EditText =< img src ='.. / .. / Common / Images / row_edit_20x20.png'border = 0 title ='Edit'>

ShowEditButton = trueButtonType =LinkShowCancelButton =falseUpdateText =< img src ='.. / .. / Common / Images / row_save_20x20.png'border = 0 title ='Save'>>



< asp:TemplateField>

< itemstyle width =10%>

< footerstyle width =10%>

< itemtemplate>

< asp:LinkBut​​ton Text =< img src ='.. / .. / Common / Images / row_delete_20x20.png'style ='border:0px'/>

runat =serverID =imgButtonDeleteToolTip =DeleteCausesValidation =false

CommandName =Delete>



< footertemplate>

< asp:LinkBut​​ton Text =< img src ='.. / .. / Common / Images / row_save_20x20.png'style ='border:0px'/> ;

runat =serverID =lnkSaveCommandName =Save>









< triggers> < asp:AsyncPostBackTrigger ControlID =btnAdd/>

< asp:AsyncPostBackTrigger ControlID =btnCancel/>




<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" />





















VB代码 - :



进口FindurBiz.Utilities

进口FindurBiz.Business.CategorySubCategory

部分公共类ManageCategory

继承FindurBizBasePage



受保护的子Page_Load(ByVal sender As Object,ByVal e As System.EventArgs)处理Me.Load

如果不是Page.IsPostBack那么

BindCategory ()

结束如果

结束子



Private Sub BindCategory()

Dim dtCategory As DataTable

尝试

dtCategory = AdminCategoryGet( )

gvCategory.DataSource = dtCategory

gvCategory.DataBind()



Catch ex As Exception



结束尝试

结束子



私有子gvCategory_RowCommand(ByVal发送者为对象, ByVal e As System.Web.UI.WebControls.GridViewCommandEventArgs)处理gvCategory.RowCommand

尝试



如果e.CommandName.Equals(保存)然后

Dim iCategoryID作为整数

Dim strCategoryName As String = String.Empty

Dim strCategoryDe​​sc 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

strCategoryDe​​sc = CType(gvCategory.FooterRow.FindControl(txtCategoryDe​​sc),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,strCategoryDe​​sc,strCategoryImage,iIsActive)

Else

Dim strImageUpload As FileUpload = CType(gvCategory.FooterRow.Fin dControl(flupImage),FileUpload)

Dim FileName As String = String.Empty

Dim strCategoryImage1 As String = String.Empty



如果(strImageUpload IsNot Nothing)那么



If(strImageUpload.HasFile)那么

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

结束如果



结束如果

结束如果



'ElseIf



Catch ex As Exception

抛出新的ApplicationException(gvArea_RowCommand,ex)

结束尝试

结束子



Private Sub gvCategory_RowDataBound(ByVal sender As Object,ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs)处理gvCategory.RowDataBound

如果e.Row.RowType = DataControlRowType.DataRow那么

'确认删除

Dim lb作为LinkBut​​ton = CType(e.Row.FindControl(imgButtonDelete),LinkBut​​ton)

lb.OnClientClick =return confirm( 你确定要删除类别类型吗?);

结束如果

结束子



Private Sub gvCategory_RowDeleting(ByVal sender As Object,ByVal e As System.Web.UI.WebControls.GridViewDeleteEventArgs)处理gvCategory.RowDeleting

Dim dsResult As DataSet

Dim CategoryID As Integer

尝试

CategoryID = CType(gvCategory.Rows(e.RowIndex)。 FindControl(lblCategoryID),Label).Text

dsResult = AdminCategoryDe​​lete(CategoryID)

如果dsResult.Tables(0).Rows.Count> 0然后

如果dsResult.Tables(0).Rows(0)(Result)<> 成功然后

Me.ShowMessage(Common.MessageStatus.Err,dsResult.Tables(0).Rows(0)(Result)。ToString(),lblMessage.ClientID,True)< br $>
退出Sub

否则

Me.ShowMessage(Common.MessageStatus.Save,类别类型已删除。,lblMessage.ClientID,True)

BindCategory()

结束如果

结束如果



Catch ex As Exception

抛出新的ApplicationException(AreaAdmin.aspx-Delete,ex)

结束尝试

结束子



Private Sub gvCategory_RowEditing(ByVal sender As Object,ByVal e As System.Web.UI.WebControls.GridViewEditEventArgs)处理gvCategory.RowEditing

gvCategory.EditIndex = e.NewEditIndex

SetupFooter(False)

gvCategory.Rows(e.NewEditIndex).FindControl(imgButton删除)。可见=错隐藏编辑

结束子



私有子gvCategory_RowUpdating(ByVal发件人作为对象,ByVal e As System .Web.UI.WebControls.GridViewUpdateEventArgs)处理gvCategory.RowUpdating

Dim iCategoryID As Integer

Dim strCategoryName As String = String.Empty

Dim strCategoryDe​​sc As String = String.Empty

Dim strCategoryImage As String = String.Empty

Dim iIsActive As Integer

Dim FileName As String = String。空的





Dim strImageUpload As FileUpload = CType(gvCategory.Rows(e.RowIndex).FindControl(flupImage),FileUpload)



if(strImageUpload.HasFile)然后

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



结束如果



iCategoryID = CType(gvCategory.Rows(e.RowIndex).FindControl(lblCategoryID),Label).Text

strCategoryName = CType(gvCategory.Rows(e.RowIndex).FindControl(txtCategoryName),TextBox).Text

strCategoryDe​​sc = CType(gvCategory.Rows(e。 RowIndex).FindControl(txtCategoryDe​​sc),TextBox).Text



'strCategoryImage = CType(gvCategory.Rows(e.RowIndex).FindControl(imgPic) ,Image).ImageUrl

Dim strCategoryImage1 As String = strCategoryImage.Substring(strCatego ryImage.LastIndexOf(/)+ 1)



iIsActive = CType(gvCategory.Rows(e.RowIndex).FindControl(ddlEditIsActive),DropDownList)。 SelectedItem.Value



CategorySave(iCategoryID,strCategoryName,strCategoryDe​​sc,strCategoryImage1,iIsActive)

gvCategory.EditIndex = -1

BindCategory()



End Sub

Private Sub CategorySave(ByVal iCategoryID As Integer,ByVal strCategoryName As String,ByVal strCategoryDe​​sc As String ,ByVal strCategoryImage As String,ByVal iIsActive As Integer)

尝试



如果不是String.IsNullOrEmpty(strCategoryName)那么

如果CheckExistingCategory(strCategoryName)那么

AdminCategoryUpdate(iCategoryID,strCategoryName,strCategoryDe​​sc,strCategoryImage,iIsActive)

Me.ShowMessage(Common.MessageStatus.Information,Categ ory信息已保存。,lblMessage.ClientID,True)

SetupFooter(False)

否则

Me.ShowMessage(Common.MessageStatus.Information ,类别名称已被使用。,lblMessage.ClientID,True)

结束如果

否则

如果gvCategory.Rows.Count< ;> 0然后

Me.ShowMessage(Common.MessageStatus.Information,类别名称是必需的。,lblMessage.ClientID,True)

否则

AdminCategoryUpdate(iCategoryID,strCategoryName,strCategoryDe​​sc,strCategoryImage,iIsActive)

结束如果



结束如果

Catch ex As Exception



结束尝试

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)处理btnAdd.Click

如果gvCategory.Rows.Count = 0然后

CategorySave(0,,,,True)

gvCategory.EditIndex = 0

Se tupFooter(假)

否则

gvCategory.EditIndex = -1

SetupFooter(True)

结束如果< br $>


结束次级





结束班级







在gridview中显示数据后,在gridview中单击编辑按钮时如果上传后的图像,则图像更改无法正常工作,因为如果条件不符合下面的代码,则不会输入...











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................

推荐答案

这篇关于如何从网格视图更改图像并更新vb中的图像?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆