双击在网格视图中显示的图像,然后双击从数据库oracle获取图像ID [英] double click on image displayed in grid view and after double click get image id from data base oracle

查看:57
本文介绍了双击在网格视图中显示的图像,然后双击从数据库oracle获取图像ID的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

双击在网格视图中显示的图像以及双击从数据库oracle获取图像ID时如何获得价值?

我的VB代码如下所示


How to get value when double click on image displayed in grid view and after double click get image id from data base oracle ?

My VB CODE IS GIVEN BELOW


Imports System.Data
Imports System.IO
Imports System.Data.OleDb
Imports System.Data.OracleClient
Imports System.Web.UI.WebControls
Imports t_tool
Imports System.Web.UI.UserControl

Partial Class ShapeInGrid
    Inherits System.Web.UI.Page
    Dim con As New OracleConnection(ConfigurationManager.ConnectionStrings("OracleConnect1").ConnectionString)
    Protected Sub Page_Load(sender As Object, e As System.EventArgs) Handles Me.Load
        con.Open()
        MsgBox(con.State)
        If Not IsPostBack Then
            populatedata()
        End If

    End Sub

    Private Sub populatedata()
        Try
            Dim sql As String
            sql = "select CTD_ORDER_ID, CTD_SHAPE_IMG from V_CAB_TAG_DTLS"
            Dim da As New OracleDataAdapter(Sql, con)
            Dim dt As New DataTable
            If Not con.State = ConnectionState.Open Then
                con.Open()
                Dim ds As New DataSet()
                da.Fill(ds)
                gvShape.DataSource = ds
                gvShape.DataBind()
            End If
            da.Fill(dt)
            con.Close()
            If dt.Rows.Count > 0 Then
                gvShape.DataSource = dt
                gvShape.DataBind()
            Else
                dt.Clear()
                gvShape.DataSource = dt
                gvShape.DataBind()
            End If
        Catch ex As Exception
            Response.Write(ex.Message)
        End Try

    End Sub



    Protected Sub gvShape_RowDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles gvShape.RowDataBound
        If e.Row.RowType = DataControlRowType.Header Then
            Dim HeaderGrid As GridView = DirectCast(sender, GridView)
            Dim HeaderGridRow As New GridViewRow(0, 0, DataControlRowType.Header, DataControlRowState.Insert)
            Dim HeaderCell As New TableCell()
            HeaderCell = New TableCell()
            HeaderCell.Text = "SHAPE CATEGORY"
            HeaderCell.ColumnSpan = e.Row.Cells.Count
            HeaderCell.HorizontalAlign = HorizontalAlign.Center
            HeaderGridRow.Cells.Add(HeaderCell)
            HeaderGridRow.BackColor = Drawing.Color.DarkBlue
            HeaderGridRow.ForeColor = Drawing.Color.White
            gvShape.Controls(0).Controls.AddAt(0, HeaderGridRow)
        End If

        If (e.Row.RowType = DataControlRowType.DataRow) Then
            If ((e.Row.RowState = DataControlRowState.Edit) _
                        OrElse (e.Row.RowState = (DataControlRowState.Edit Or DataControlRowState.Alternate))) Then
                e.Row.Attributes.Clear()
            Else
                Dim cellIndex As Integer = 2
                Do While (cellIndex < e.Row.Cells.Count)
                    Dim _doubleClickButton As LinkButton = CType(e.Row.Cells(0).Controls(0), LinkButton)
                    ' Get the javascript which is assigned to this LinkButton
                    Dim _jsDouble As String = ClientScript.GetPostBackClientHyperlink(_doubleClickButton, "")
                    ' Add the cell index as the event argument parameter
                    _jsDouble = _jsDouble.Insert((_jsDouble.Length - 2), cellIndex.ToString)
                    ' Add this javascript to the ondblclick Attribute of the row
                    e.Row.Cells(cellIndex).Attributes("ondblclick") = _jsDouble
                    cellIndex = (cellIndex + 1)
                Loop
            End If
        End If

    End Sub

    Protected Sub gvShape_SelectedIndexChanging(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewSelectEventArgs) Handles gvShape.SelectedIndexChanging
        Dim value As String = gvShape.Rows(e.NewSelectedIndex.ToString()).Cells(1).Text
        Label1.Text = value
        gvShape.SelectedIndex = e.NewSelectedIndex
        'Dim id As String = gvShape.Rows(e.RowIndex).Cells(1).Text
        Dim id As String = gvShape.Rows(e.NewSelectedIndex).Cells(1).Text
        populatedata()
        Label2.Text = gvShape.SelectedIndex
    End Sub


    Protected Sub gvShape_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles gvShape.SelectedIndexChanged

    End Sub

    Protected Sub gvShape_RowCommand(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewCommandEventArgs) Handles gvShape.RowCommand
        Dim _gridView As GridView = CType(sender, GridView)
        _gridView.EditIndex = -1
        ' Get the selected index and the command name
        Dim _selectedIndex As Integer = Integer.Parse(e.CommandArgument.ToString)
        Dim _commandName As String = e.CommandName
        Dim _eventArgument As String = Request.Form("__EVENTARGUMENT")
        Select Case (_commandName)
            Case "DoubleClick"
                _gridView.EditIndex = _selectedIndex
                _gridView.SelectedIndex = -1
                'populatedata()

                Dim a As String
                Dim b As String
                Dim c As String
                Dim d As String
                'Label1.Text = gvShape.SelectedRow.Cells(0).Text
                'b = gvShape.SelectedRow.Cells(0).Text
                'c = gvShape.SelectedRow.Cells(0).Text
                'd = gvShape.SelectedRow.Cells(0).Text
                MsgBox(gvShape.SelectedRow.Cells(1).Text)
                'gvShape.DataBind()

                Dim CellValue As String = CStr(row("SupplierID"))
                'Label2.Text = (Label1.Text + ("Double clicked GridView row at index " _
                '            + (_selectedIndex.ToString + (" on cell index " _
                '            + (_eventArgument + "<br />")))))
        End Select
    End Sub
    Protected Overrides Sub Render(ByVal writer As HtmlTextWriter)
        ' The client scripts for GridView1 were created in GridView1_RowDataBound
        For Each r As GridViewRow In gvShape.Rows
            If (r.RowType = DataControlRowType.DataRow) Then
                Dim cellIndex As Integer = 2
                Do While (cellIndex < r.Cells.Count)
                    Page.ClientScript.RegisterForEventValidation((r.UniqueID + "$ctl00"), cellIndex.ToString)
                    Page.ClientScript.RegisterForEventValidation((r.UniqueID + "$ctl01"), cellIndex.ToString)
                    cellIndex = (cellIndex + 1)
                Loop
            End If
        Next
        MyBase.Render(writer)
    End Sub

    Private Sub gvShape_RowCreated(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles gvShape.RowCreated

        For Each control As Control In e.Row.Cells(1).Controls
            If TypeOf control Is System.Web.UI.WebControls.Image Then

                Dim image As Image = DirectCast(control, System.Web.UI.WebControls.Image)

                Dim sql As String
                sql = "select CTD_ORDER_ID from V_CAB_TAG_DTLS where CTD_SHAPE_IMG= image "
                Dim da As New OracleDataAdapter(sql, con)
                Dim dt As New DataTable
                If Not con.State = ConnectionState.Open Then
                    con.Open()
                    Dim ds As New DataSet()
                    da.Fill(ds)
                    gvShape.DataSource = ds
                    gvShape.DataBind()
                End If
                da.Fill(dt)
                con.Close()
                If dt.Rows.Count > 0 Then
                    gvShape.DataSource = dt
                    gvShape.DataBind()
                Else
                    dt.Clear()
                    gvShape.DataSource = dt
                    gvShape.DataBind()
                End If
            End If
        Next

    End Sub

End Class





我的HTMLS代码如下所示






MY HTMLS CODE IS GIVEN BELOW


<%@ Page Language="VB" AutoEventWireup="false" CodeFile="ShapeInGrid.aspx.vb" Inherits="ShapeInGrid" EnableEventValidation="false" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <div align="center">
        &nbsp;<br />
                <asp:GridView ID="gvShape" runat="server" AutoGenerateColumns="False" Width ="100 px"

            CellPadding="4" Font-Names="calibri" Font-Size="Small" ForeColor="#333333">
            <RowStyle BackColor="#EFF3FB" Font-Names="calibri" HorizontalAlign="Left" />
            <Columns>
            <asp:ButtonField Text="SingleClick" CommandName="SingleClick" Visible="false"/>
                <asp:ButtonField Text="DoubleClick" CommandName="DoubleClick" Visible="false"/>
                <asp:TemplateField HeaderText="PHOTO">
                        <ItemTemplate>
                        <asp:Image ID="Image1" runat="server" Height="50" ImageUrl='<%# "ShapHandler.ashx?ImID=" + Eval("CTD_ORDER_ID") %>'

                            Width="50" />
                    </ItemTemplate>
                </asp:TemplateField>
            </Columns>
            <FooterStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
            <PagerStyle BackColor="#2461BF" ForeColor="White" HorizontalAlign="Center" />
            <SelectedRowStyle BackColor="#D1DDF1" Font-Bold="True" ForeColor="#333333" />
            <HeaderStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" HorizontalAlign="Left" />
            <EditRowStyle BackColor="#2461BF" />
            <AlternatingRowStyle BackColor="White" BorderStyle="None" />
        </asp:GridView>
        <br />
        <br />
        <asp:Label ID="Label1" runat="server" Text="Label"></asp:Label><br />
        <br />
        <asp:Label ID="Label2" runat="server" Text="Label"></asp:Label>

    </div>
    </form>
</body>

推荐答案

ctl00"),cellIndex.ToString) Page.ClientScript.RegisterForEventValidation((r.UniqueID + "
ctl00"), cellIndex.ToString) Page.ClientScript.RegisterForEventValidation((r.UniqueID + "


ctl01" )、cellIndex.ToString) cellIndex =(cellIndex + 1 ) 循环 结束 如果 下一步 MyBase .Render(编写器) 结束 私有 gvShape_RowCreated( ByVal 发​​件人目标 对象 ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs)对于 每个控件 As 控件 e.Row.Cells( 1 )中. 如果 TypeOf 控件 System.Web. UI.WebControls.Image 然后 Dim 图片 As 图片= DirectCast ( ,System.Web.UI.WebControls.Image) Dim sql As String sql = " Dim da As New OracleDataAdapter(sql,骗局) Dim dt As New DataTable 如果 con.State = ConnectionState.打开然后 con.Open() Dim ds As 新建 DataSet() da.Fill(ds) gvShape.DataSource = ds gvShape.DataBind() 结束 如果 da.Fill(dt) con.Close() 如果 dt.Rows.Count> 0 然后 gvShape.DataSource = dt gvShape.DataBind() 其他 dt.Clear() gvShape.DataSource = dt gvShape.DataBind() 结束 如果 结束 如果 下一步 结束 结束
ctl01"), cellIndex.ToString) cellIndex = (cellIndex + 1) Loop End If Next MyBase.Render(writer) End Sub Private Sub gvShape_RowCreated(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles gvShape.RowCreated For Each control As Control In e.Row.Cells(1).Controls If TypeOf control Is System.Web.UI.WebControls.Image Then Dim image As Image = DirectCast(control, System.Web.UI.WebControls.Image) Dim sql As String sql = "select CTD_ORDER_ID from V_CAB_TAG_DTLS where CTD_SHAPE_IMG= image " Dim da As New OracleDataAdapter(sql, con) Dim dt As New DataTable If Not con.State = ConnectionState.Open Then con.Open() Dim ds As New DataSet() da.Fill(ds) gvShape.DataSource = ds gvShape.DataBind() End If da.Fill(dt) con.Close() If dt.Rows.Count > 0 Then gvShape.DataSource = dt gvShape.DataBind() Else dt.Clear() gvShape.DataSource = dt gvShape.DataBind() End If End If Next End Sub End Class





我的HTMLS代码如下所示






MY HTMLS CODE IS GIVEN BELOW


<%@ Page Language="VB" AutoEventWireup="false" CodeFile="ShapeInGrid.aspx.vb" Inherits="ShapeInGrid" EnableEventValidation="false" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <div align="center">
        &nbsp;<br />
                <asp:GridView ID="gvShape" runat="server" AutoGenerateColumns="False" Width ="100 px"

            CellPadding="4" Font-Names="calibri" Font-Size="Small" ForeColor="#333333">
            <RowStyle BackColor="#EFF3FB" Font-Names="calibri" HorizontalAlign="Left" />
            <Columns>
            <asp:ButtonField Text="SingleClick" CommandName="SingleClick" Visible="false"/>
                <asp:ButtonField Text="DoubleClick" CommandName="DoubleClick" Visible="false"/>
                <asp:TemplateField HeaderText="PHOTO">
                        <ItemTemplate>
                        <asp:Image ID="Image1" runat="server" Height="50" ImageUrl='<%# "ShapHandler.ashx?ImID=" + Eval("CTD_ORDER_ID") %>'

                            Width="50" />
                    </ItemTemplate>
                </asp:TemplateField>
            </Columns>
            <FooterStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
            <PagerStyle BackColor="#2461BF" ForeColor="White" HorizontalAlign="Center" />
            <SelectedRowStyle BackColor="#D1DDF1" Font-Bold="True" ForeColor="#333333" />
            <HeaderStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" HorizontalAlign="Left" />
            <EditRowStyle BackColor="#2461BF" />
            <AlternatingRowStyle BackColor="White" BorderStyle="None" />
        </asp:GridView>
        <br />
        <br />
        <asp:Label ID="Label1" runat="server" Text="Label"></asp:Label><br />
        <br />
        <asp:Label ID="Label2" runat="server" Text="Label"></asp:Label>

    </div>
    </form>
</body>



几年前,我遇到了同样的问题.
终于,我们做了个把戏.
在初始qry本身中获取图像ID,并
行数据绑定事件中,将该id列的可见性样式设置为false.

然后,如您所知,您可以更改所选索引或行命令事件中的ID.
希望这会有所帮助.
Hi,
I was running out the same issue some years ago.
Finally we did a trick.
get the image id in initial qry itself and
in row data bound event set the visibility style for that id column to false.

Then as you know you can get the id in selected index changed or row command event.
Hope this helps.


这篇关于双击在网格视图中显示的图像,然后双击从数据库oracle获取图像ID的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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