Recently I updated a website from framework 3.5 to 4.0. Everithing works fine, except a update to a grid.
I have a grid that I update using a panel below with textboxs and a save button that updates and realoads the grid.
The first time I save everithing works fine. The second time I try to save any of the rows, when the grid reloads, the row that as been update is show as a edit row inline the grid, with a textbox for every column inside the grid row, load with the grid
column/row data.
The funny thing is that if I tried to make this point on the grid would not know how.
Protected Sub GridView1_RowDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles GridView1.RowDataBound
'----------------------------------------------------
'Só deixa editar as duas últimas duas linhas de registo
Dim myImgB As WebControls.ImageButton = CType(e.Row.FindControl("ImgBEditar"), WebControls.ImageButton)
If e.Row.RowType = DataControlRowType.DataRow Then
If Not Me.PanelAdmin.Visible Then
'-----------------------------------------------------
If e.Row.DataItemIndex <= 1 Then
If Not myImgB.Visible Then
myImgB.Visible = True
End If
End If
'-----------------------------------------------------
Else
myImgB.Visible = True
End If
End If
'-----------------------------------------------------
'mostra o icon com info de SA processado
'Dim teste As String
'Dim myImgVD As WebControls.Image = CType(e.Row.FindControl("Image1"), WebControls.Image)
'If e.Row.RowType = DataControlRowType.DataRow Then
' teste = myF.DevolveDescricao("Registo", "NrVDRefeicao", "IdRP", GridView1.DataKeys(e.Row.DataItemIndex).Item(0), Lig)
' If teste <> "" Then
' myImgVD.Visible = True
' Else
' myImgVD.Visible = False
' End If
'End If
'-----------------------------------------------------
End Sub
Protected Sub GridView1_RowEditing(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewEditEventArgs) Handles GridView1.RowEditing
Call Limpeza()
'edição das linhas
Me.Panel.Visible = True
Me.TxtVD.Enabled = False
Me.LblIdRP.Text = GridView1.DataKeys(e.NewEditIndex).Item(0)
Me.LblIdUtilizador.Text = GridView1.DataKeys(e.NewEditIndex).Item(1)
'IIf(GridView1.Rows(e.NewEditIndex).Cells(2).Text = " ", "", GridView1.Rows(e.NewEditIndex).Cells(2).Text)
Me.LblData.Text = IIf(GridView1.Rows(e.NewEditIndex).Cells(4).Text = " ", "", GridView1.Rows(e.NewEditIndex).Cells(4).Text)
Me.TxtHE1.Text = IIf(GridView1.Rows(e.NewEditIndex).Cells(6).Text = " ", "", GridView1.Rows(e.NewEditIndex).Cells(6).Text)
Me.TxtHS1.Text = IIf(GridView1.Rows(e.NewEditIndex).Cells(7).Text = " ", "", GridView1.Rows(e.NewEditIndex).Cells(7).Text)
Me.TxtHE2.Text = IIf(GridView1.Rows(e.NewEditIndex).Cells(8).Text = " ", "", GridView1.Rows(e.NewEditIndex).Cells(8).Text)
Me.TxtHS2.Text = IIf(GridView1.Rows(e.NewEditIndex).Cells(9).Text = " ", "", GridView1.Rows(e.NewEditIndex).Cells(9).Text)
Me.TxtObs.Text = IIf(GridView1.Rows(e.NewEditIndex).Cells(10).Text = " ", "", GridView1.Rows(e.NewEditIndex).Cells(10).Text)
Me.LblES.Text = IIf(GridView1.Rows(e.NewEditIndex).Cells(11).Text = " ", "", GridView1.Rows(e.NewEditIndex).Cells(11).Text)
'Me.TxtVD.Text = IIf(GridView1.Rows(e.NewEditIndex).Cells(12).Text = " ", "", GridView1.Rows(e.NewEditIndex).Cells(12).Text)
'Me.TxtVD.Text = myF.DevolveDescricao("Registo", "NrVDRefeicao", "IdRP", Me.LblIdRP.Text, Lig)
'teste utilizador + limitado
'Dim T
'T = myF.DevolveDescricao("Utilizadores", "Tesoureiro", "IdUtilizador", Session("EntradaLogin"), Lig)
'If T And Me.PanelAdmin.Visible And DlDep.Enabled = False Then
' Me.TxtObs.Enabled = False
'End If
'-----------------------------------------------------
If Session("Periodo") = 1 Then
Panel2.Visible = False
Else
Panel2.Visible = True
End If
If Me.PanelAdmin.Visible Then
'mostra as datahora/users da ultima alteração
Me.LblHE1.Text = myRP.DevolveUltimaAlteracao(LblIdRP.Text, 1)
Me.LblHS1.Text = myRP.DevolveUltimaAlteracao(LblIdRP.Text, 2)
Me.LblHE2.Text = myRP.DevolveUltimaAlteracao(LblIdRP.Text, 3)
Me.LblHS2.Text = myRP.DevolveUltimaAlteracao(LblIdRP.Text, 4)
'Me.TxtVD.Enabled = True
End If
GridView1.SelectedIndex = e.NewEditIndex
'--------------------------------------
'Call PosicaoHoras()
If Not Me.PanelAdmin.Visible Then
Page.SetFocus(TxtObs)
Else ' deixa que um utilizar do tipo admin, possa rectificar o horário
Me.TxtHE1.Enabled = True
Me.TxtHS1.Enabled = True
End If
End Sub
'carrega as grid's existentes no form
Public Sub CarregaGrid(ByVal argGrid As GridView, ByVal argEmpresa As String, ByVal argData1 As Date, ByVal argData2 As Date, ByVal argUser As String, ByVal NR As Integer, Optional ByVal argDep As Integer = 0, Optional ByVal sp As Boolean = False, Optional ByVal UDep As Integer = 0)
'-----------------------------------------------------------
Dim CommandText As String = ""
Dim Conexao As OdbcConnection = New OdbcConnection(Ligacao)
Dim meuAdaptador As OdbcDataAdapter
Dim meuDataSet As DataSet
If NR = 0 Then
If argUser > 0 Then 'Utilizador
If argData1 <> Nothing And argData2 <> Nothing Then
CommandText = " SELECT Registo.*, Utilizadores.Nome AS AliasUtilizador" & _
" FROM Utilizadores RIGHT JOIN Registo ON Utilizadores.IdUtilizador = Registo.IdUtilizador" & _
" Where Registo.IdEmpresa=" & argEmpresa & " and Data >=#" & Month(argData1) & "-" & Day(argData1) & "-" & Year(argData1) & "#" & _
" And Data <=#" & Month(argData2) & "-" & Day(argData2) & "-" & Year(argData2) & "#" & _
" AND Registo.IdUtilizador=" & argUser & _
" ORDER BY Utilizadores.Nome, Registo.Data DESC,Registo.HE1;"
Else
CommandText = " SELECT Registo.*, Utilizadores.Nome AS AliasUtilizador" & _
" FROM Utilizadores RIGHT JOIN Registo ON Utilizadores.IdUtilizador = Registo.IdUtilizador" & _
" Where Registo.IdEmpresa=" & argEmpresa & " and Data <=" & DateAdd(DateInterval.Day, -30, Date.Today) & _
" AND Registo.IdUtilizador=" & argUser & _
" ORDER BY Utilizadores.Nome, Registo.Data DESC,Registo.HE1;"
End If
Else ' TODOS
If argData1 <> Nothing And argData2 <> Nothing Then
If argDep = 0 And argDep = Nothing Then
CommandText = " SELECT Registo.*, Utilizadores.Nome AS AliasUtilizador" & _
" FROM Utilizadores RIGHT JOIN Registo ON Utilizadores.IdUtilizador = Registo.IdUtilizador" & _
" Where Registo.IdEmpresa=" & argEmpresa & " and Data >=#" & Month(argData1) & "-" & Day(argData1) & "-" & Year(argData1) & "#" & _
" And Data <=#" & Month(argData2) & "-" & Day(argData2) & "-" & Year(argData2) & "#" & _
" ORDER BY Utilizadores.Nome, Registo.Data,Registo.HE1;"
Else
CommandText = " SELECT Registo.*, Utilizadores.Nome AS AliasUtilizador" & _
" FROM Utilizadores RIGHT JOIN Registo ON Utilizadores.IdUtilizador = Registo.IdUtilizador" & _
" Where Registo.IdEmpresa=" & argEmpresa & " and Data >=#" & Month(argData1) & "-" & Day(argData1) & "-" & Year(argData1) & "#" & _
" And Data <=#" & Month(argData2) & "-" & Day(argData2) & "-" & Year(argData2) & "#" & _
" And Dep=" & argDep & _
" ORDER BY Utilizadores.Nome, Registo.Data,Registo.HE1;"
End If
Else
If argDep = 0 And argDep = Nothing Then
CommandText = " SELECT Registo.*, Utilizadores.Nome AS AliasUtilizador" & _
" FROM Utilizadores RIGHT JOIN Registo ON Utilizadores.IdUtilizador = Registo.IdUtilizador" & _
" Where Registo.IdEmpresa=" & argEmpresa & _
" ORDER BY Utilizadores.Nome, Registo.Data,Registo.HE1;"
Else
CommandText = " SELECT Registo.*, Utilizadores.Nome AS AliasUtilizador" & _
" FROM Utilizadores RIGHT JOIN Registo ON Utilizadores.IdUtilizador = Registo.IdUtilizador" & _
" Where Registo.IdEmpresa=" & argEmpresa & _
" And Dep=" & argDep & _
" ORDER BY Utilizadores.Nome, Registo.Data,Registo.HE1;"
End If
End If
End If
Else
CommandText = "Select TOP 8 *,(select Nome From Utilizadores Where IdUtilizador=Registo.IdUtilizador) as AliasUtilizador From Registo" & _
" Where IdEmpresa=" & argEmpresa & _
" AND IdUtilizador=" & argUser & " Order by Data DESC;"
'CommandText = " SELECT Registo.*, Utilizadores.Nome AS AliasUtilizador" & _
'" FROM Utilizadores RIGHT JOIN Registo ON Utilizadores.IdUtilizador = Registo.IdUtilizador" & _
'" Where Registo.IdEmpresa=" & argEmpresa & " AND Registo.IdUtilizador=" & argUser & _
'" And month(Data)=" & Month(Date.Today) & _
'" ORDER BY Utilizadores.Nome, Registo.Data DESC,Registo.HE1;"
End If
'-----------------------------------------------------------
Try
Conexao.Open()
Catch
If (Conexao.State = ConnectionState.Open) Then
Conexao.Close()
End If
End Try
meuAdaptador = New OdbcDataAdapter(CommandText, Conexao)
meuDataSet = New DataSet
meuAdaptador.Fill(meuDataSet)
argGrid.DataSource = meuDataSet
argGrid.DataBind()
Conexao.Close()
End Sub
hi, i will suggest you to change the commandname of image button from Edit to Show (or whatever name based on your req. other than Edit). bcos in asp.net .4.0, Edit automatically renders the TextBox in edit mode
R2
Member
96 Points
96 Posts
GridView Problem Framework 4.0
Nov 05, 2012 10:19 AM|LINK
Recently I updated a website from framework 3.5 to 4.0. Everithing works fine, except a update to a grid.
I have a grid that I update using a panel below with textboxs and a save button that updates and realoads the grid.
The first time I save everithing works fine. The second time I try to save any of the rows, when the grid reloads, the row that as been update is show as a edit row inline the grid, with a textbox for every column inside the grid row, load with the grid column/row data.
The funny thing is that if I tried to make this point on the grid would not know how.
Any Ideias abou what is happening?
Thanks in advance.
sarathi125
Star
13599 Points
2691 Posts
Re: GridView Problem Framework 4.0
Nov 05, 2012 02:39 PM|LINK
Hi,
I think You might have added some new event for the gridview..
Post your code here for better help.
Remember to click Mark as Answer on the post that helps to others.
My Blog :MyAspSnippets
R2
Member
96 Points
96 Posts
Re: GridView Problem Framework 4.0
Nov 06, 2012 08:13 AM|LINK
Here is my Code:
Grid's Events that I'm using:
Protected Sub GridView1_RowDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles GridView1.RowDataBound '---------------------------------------------------- 'Só deixa editar as duas últimas duas linhas de registo Dim myImgB As WebControls.ImageButton = CType(e.Row.FindControl("ImgBEditar"), WebControls.ImageButton) If e.Row.RowType = DataControlRowType.DataRow Then If Not Me.PanelAdmin.Visible Then '----------------------------------------------------- If e.Row.DataItemIndex <= 1 Then If Not myImgB.Visible Then myImgB.Visible = True End If End If '----------------------------------------------------- Else myImgB.Visible = True End If End If '----------------------------------------------------- 'mostra o icon com info de SA processado 'Dim teste As String 'Dim myImgVD As WebControls.Image = CType(e.Row.FindControl("Image1"), WebControls.Image) 'If e.Row.RowType = DataControlRowType.DataRow Then ' teste = myF.DevolveDescricao("Registo", "NrVDRefeicao", "IdRP", GridView1.DataKeys(e.Row.DataItemIndex).Item(0), Lig) ' If teste <> "" Then ' myImgVD.Visible = True ' Else ' myImgVD.Visible = False ' End If 'End If '----------------------------------------------------- End Sub Protected Sub GridView1_RowEditing(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewEditEventArgs) Handles GridView1.RowEditing Call Limpeza() 'edição das linhas Me.Panel.Visible = True Me.TxtVD.Enabled = False Me.LblIdRP.Text = GridView1.DataKeys(e.NewEditIndex).Item(0) Me.LblIdUtilizador.Text = GridView1.DataKeys(e.NewEditIndex).Item(1) 'IIf(GridView1.Rows(e.NewEditIndex).Cells(2).Text = " ", "", GridView1.Rows(e.NewEditIndex).Cells(2).Text) Me.LblData.Text = IIf(GridView1.Rows(e.NewEditIndex).Cells(4).Text = " ", "", GridView1.Rows(e.NewEditIndex).Cells(4).Text) Me.TxtHE1.Text = IIf(GridView1.Rows(e.NewEditIndex).Cells(6).Text = " ", "", GridView1.Rows(e.NewEditIndex).Cells(6).Text) Me.TxtHS1.Text = IIf(GridView1.Rows(e.NewEditIndex).Cells(7).Text = " ", "", GridView1.Rows(e.NewEditIndex).Cells(7).Text) Me.TxtHE2.Text = IIf(GridView1.Rows(e.NewEditIndex).Cells(8).Text = " ", "", GridView1.Rows(e.NewEditIndex).Cells(8).Text) Me.TxtHS2.Text = IIf(GridView1.Rows(e.NewEditIndex).Cells(9).Text = " ", "", GridView1.Rows(e.NewEditIndex).Cells(9).Text) Me.TxtObs.Text = IIf(GridView1.Rows(e.NewEditIndex).Cells(10).Text = " ", "", GridView1.Rows(e.NewEditIndex).Cells(10).Text) Me.LblES.Text = IIf(GridView1.Rows(e.NewEditIndex).Cells(11).Text = " ", "", GridView1.Rows(e.NewEditIndex).Cells(11).Text) 'Me.TxtVD.Text = IIf(GridView1.Rows(e.NewEditIndex).Cells(12).Text = " ", "", GridView1.Rows(e.NewEditIndex).Cells(12).Text) 'Me.TxtVD.Text = myF.DevolveDescricao("Registo", "NrVDRefeicao", "IdRP", Me.LblIdRP.Text, Lig) 'teste utilizador + limitado 'Dim T 'T = myF.DevolveDescricao("Utilizadores", "Tesoureiro", "IdUtilizador", Session("EntradaLogin"), Lig) 'If T And Me.PanelAdmin.Visible And DlDep.Enabled = False Then ' Me.TxtObs.Enabled = False 'End If '----------------------------------------------------- If Session("Periodo") = 1 Then Panel2.Visible = False Else Panel2.Visible = True End If If Me.PanelAdmin.Visible Then 'mostra as datahora/users da ultima alteração Me.LblHE1.Text = myRP.DevolveUltimaAlteracao(LblIdRP.Text, 1) Me.LblHS1.Text = myRP.DevolveUltimaAlteracao(LblIdRP.Text, 2) Me.LblHE2.Text = myRP.DevolveUltimaAlteracao(LblIdRP.Text, 3) Me.LblHS2.Text = myRP.DevolveUltimaAlteracao(LblIdRP.Text, 4) 'Me.TxtVD.Enabled = True End If GridView1.SelectedIndex = e.NewEditIndex '-------------------------------------- 'Call PosicaoHoras() If Not Me.PanelAdmin.Visible Then Page.SetFocus(TxtObs) Else ' deixa que um utilizar do tipo admin, possa rectificar o horário Me.TxtHE1.Enabled = True Me.TxtHS1.Enabled = True End If End SubGrid's Definition:
<asp:Panel ID="PanelScrollMed" runat="server" Height="180px" HorizontalAlign="Center" ScrollBars="Vertical" Width="100%"> <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" BorderColor="Silver" BorderStyle="Solid" BorderWidth="1px" CellPadding="4" DataKeyNames="IdRP,IdUtilizador" ForeColor="#333333" GridLines="None" HorizontalAlign="Left" Width="97%" ClientIDMode="AutoID" ViewStateMode="Enabled"><FooterStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" /><RowStyle BackColor="LightGray" /><Columns><asp:BoundField DataField="IdRP" HeaderText="IdRP" Visible="False" /><asp:BoundField DataField="IdEmpresa" HeaderText="IdEmpresa" Visible="False" /><asp:BoundField DataField="IdUtilizador" HeaderText="IdUtilizador" Visible="False" /><asp:BoundField DataField="AliasUtilizador" HeaderText="Utilizador"><ItemStyle VerticalAlign="Middle" Width="100px" /></asp:BoundField><asp:BoundField DataField="Data" DataFormatString="{0:dd/MM/yyyy}" HeaderText="Data" HtmlEncode="False"><ItemStyle HorizontalAlign="Center" VerticalAlign="Middle" Width="60px" Wrap="False" /></asp:BoundField><asp:BoundField DataField="Data" DataFormatString="{0:dddd}" HeaderText="Dia" HtmlEncode="False"><ItemStyle HorizontalAlign="Center" VerticalAlign="Middle" Width="60px" Wrap="False" /></asp:BoundField><asp:BoundField DataField="HE1" DataFormatString="{0:HH:mm}" HeaderText="Entrada" HtmlEncode="False"><ItemStyle HorizontalAlign="Center" VerticalAlign="Middle" Width="50px" /></asp:BoundField><asp:BoundField DataField="HS1" DataFormatString="{0:HH:mm}" HeaderText="Saída" HtmlEncode="False"><ItemStyle HorizontalAlign="Center" VerticalAlign="Middle" Width="50px" /></asp:BoundField><asp:BoundField DataField="HE2" DataFormatString="{0:HH:mm}" HeaderText="Entrada" HtmlEncode="False" Visible="False"><ItemStyle HorizontalAlign="Center" /></asp:BoundField><asp:BoundField DataField="HS2" DataFormatString="{0:HH:mm}" HeaderText="Saída" HtmlEncode="False" Visible="False"><ItemStyle HorizontalAlign="Center" /></asp:BoundField><asp:BoundField DataField="Obs" HeaderText="Obs" HtmlEncode="False"><ItemStyle HorizontalAlign="Left" VerticalAlign="Middle" Width="50px" Wrap="False" /></asp:BoundField><asp:BoundField DataField="ES" HeaderText="E/S" HtmlEncode="False"><ItemStyle HorizontalAlign="Justify" VerticalAlign="Middle" Width="60px" Wrap="False" /></asp:BoundField> <asp:TemplateField ShowHeader="False"><ItemTemplate><asp:ImageButton ID="ImgBEditar" runat="server" CausesValidation="False" CommandName="Edit" ImageUrl="~/images/geditar.gif" Text="Editar" ToolTip="Editar registo" Visible="False" /></ItemTemplate><ItemStyle HorizontalAlign="Right" VerticalAlign="Middle" Width="10px" /></asp:TemplateField> <asp:TemplateField HeaderText="S.A." Visible="False"><ItemTemplate><asp:Image ID="Image1" runat="server" Height="15px" ImageUrl="~/images/sa.gif" Width="16px" /></ItemTemplate><ItemStyle Width="10px" /></asp:TemplateField></Columns> <PagerStyle BackColor="#2461BF" ForeColor="White" HorizontalAlign="Center" /><SelectedRowStyle BackColor="Gray" Font-Bold="True" ForeColor="White" /><HeaderStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" /><EditRowStyle BackColor="#2461BF" /><AlternatingRowStyle BackColor="AliceBlue" /></asp:GridView><asp:GridView ID="GridView3" runat="server" AutoGenerateColumns="False" BorderColor="Silver" BorderStyle="Solid" BorderWidth="1px" CellPadding="4" ForeColor="#333333" GridLines="None" HorizontalAlign="Left" Visible="False" Width="97%"><FooterStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" /><RowStyle BackColor="LightGray" /><Columns><asp:BoundField DataField="IdUtilizador" HeaderText="IdUtilizador" Visible="False" /><asp:BoundField DataField="Nome" HeaderText="Utilizador"><ItemStyle VerticalAlign="Middle" Width="100px" /></asp:BoundField></Columns><PagerStyle BackColor="#2461BF" ForeColor="White" HorizontalAlign="Center" /><SelectedRowStyle BackColor="Gray" Font-Bold="True" ForeColor="White" /><HeaderStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" /><EditRowStyle BackColor="#2461BF" /><AlternatingRowStyle BackColor="AliceBlue" /></asp:GridView> </asp:Panel>Function that reload's Grid:
'carrega as grid's existentes no form Public Sub CarregaGrid(ByVal argGrid As GridView, ByVal argEmpresa As String, ByVal argData1 As Date, ByVal argData2 As Date, ByVal argUser As String, ByVal NR As Integer, Optional ByVal argDep As Integer = 0, Optional ByVal sp As Boolean = False, Optional ByVal UDep As Integer = 0) '----------------------------------------------------------- Dim CommandText As String = "" Dim Conexao As OdbcConnection = New OdbcConnection(Ligacao) Dim meuAdaptador As OdbcDataAdapter Dim meuDataSet As DataSet If NR = 0 Then If argUser > 0 Then 'Utilizador If argData1 <> Nothing And argData2 <> Nothing Then CommandText = " SELECT Registo.*, Utilizadores.Nome AS AliasUtilizador" & _ " FROM Utilizadores RIGHT JOIN Registo ON Utilizadores.IdUtilizador = Registo.IdUtilizador" & _ " Where Registo.IdEmpresa=" & argEmpresa & " and Data >=#" & Month(argData1) & "-" & Day(argData1) & "-" & Year(argData1) & "#" & _ " And Data <=#" & Month(argData2) & "-" & Day(argData2) & "-" & Year(argData2) & "#" & _ " AND Registo.IdUtilizador=" & argUser & _ " ORDER BY Utilizadores.Nome, Registo.Data DESC,Registo.HE1;" Else CommandText = " SELECT Registo.*, Utilizadores.Nome AS AliasUtilizador" & _ " FROM Utilizadores RIGHT JOIN Registo ON Utilizadores.IdUtilizador = Registo.IdUtilizador" & _ " Where Registo.IdEmpresa=" & argEmpresa & " and Data <=" & DateAdd(DateInterval.Day, -30, Date.Today) & _ " AND Registo.IdUtilizador=" & argUser & _ " ORDER BY Utilizadores.Nome, Registo.Data DESC,Registo.HE1;" End If Else ' TODOS If argData1 <> Nothing And argData2 <> Nothing Then If argDep = 0 And argDep = Nothing Then CommandText = " SELECT Registo.*, Utilizadores.Nome AS AliasUtilizador" & _ " FROM Utilizadores RIGHT JOIN Registo ON Utilizadores.IdUtilizador = Registo.IdUtilizador" & _ " Where Registo.IdEmpresa=" & argEmpresa & " and Data >=#" & Month(argData1) & "-" & Day(argData1) & "-" & Year(argData1) & "#" & _ " And Data <=#" & Month(argData2) & "-" & Day(argData2) & "-" & Year(argData2) & "#" & _ " ORDER BY Utilizadores.Nome, Registo.Data,Registo.HE1;" Else CommandText = " SELECT Registo.*, Utilizadores.Nome AS AliasUtilizador" & _ " FROM Utilizadores RIGHT JOIN Registo ON Utilizadores.IdUtilizador = Registo.IdUtilizador" & _ " Where Registo.IdEmpresa=" & argEmpresa & " and Data >=#" & Month(argData1) & "-" & Day(argData1) & "-" & Year(argData1) & "#" & _ " And Data <=#" & Month(argData2) & "-" & Day(argData2) & "-" & Year(argData2) & "#" & _ " And Dep=" & argDep & _ " ORDER BY Utilizadores.Nome, Registo.Data,Registo.HE1;" End If Else If argDep = 0 And argDep = Nothing Then CommandText = " SELECT Registo.*, Utilizadores.Nome AS AliasUtilizador" & _ " FROM Utilizadores RIGHT JOIN Registo ON Utilizadores.IdUtilizador = Registo.IdUtilizador" & _ " Where Registo.IdEmpresa=" & argEmpresa & _ " ORDER BY Utilizadores.Nome, Registo.Data,Registo.HE1;" Else CommandText = " SELECT Registo.*, Utilizadores.Nome AS AliasUtilizador" & _ " FROM Utilizadores RIGHT JOIN Registo ON Utilizadores.IdUtilizador = Registo.IdUtilizador" & _ " Where Registo.IdEmpresa=" & argEmpresa & _ " And Dep=" & argDep & _ " ORDER BY Utilizadores.Nome, Registo.Data,Registo.HE1;" End If End If End If Else CommandText = "Select TOP 8 *,(select Nome From Utilizadores Where IdUtilizador=Registo.IdUtilizador) as AliasUtilizador From Registo" & _ " Where IdEmpresa=" & argEmpresa & _ " AND IdUtilizador=" & argUser & " Order by Data DESC;" 'CommandText = " SELECT Registo.*, Utilizadores.Nome AS AliasUtilizador" & _ '" FROM Utilizadores RIGHT JOIN Registo ON Utilizadores.IdUtilizador = Registo.IdUtilizador" & _ '" Where Registo.IdEmpresa=" & argEmpresa & " AND Registo.IdUtilizador=" & argUser & _ '" And month(Data)=" & Month(Date.Today) & _ '" ORDER BY Utilizadores.Nome, Registo.Data DESC,Registo.HE1;" End If '----------------------------------------------------------- Try Conexao.Open() Catch If (Conexao.State = ConnectionState.Open) Then Conexao.Close() End If End Try meuAdaptador = New OdbcDataAdapter(CommandText, Conexao) meuDataSet = New DataSet meuAdaptador.Fill(meuDataSet) argGrid.DataSource = meuDataSet argGrid.DataBind() Conexao.Close() End Subkarthicks
All-Star
31378 Points
5422 Posts
Re: GridView Problem Framework 4.0
Nov 06, 2012 09:12 AM|LINK
hi, i will suggest you to change the commandname of image button from Edit to Show (or whatever name based on your req. other than Edit). bcos in asp.net .4.0, Edit automatically renders the TextBox in edit mode
<asp:ImageButton ID="ImgBEditar"
runat="server" CausesValidation="False" CommandName="Show" CommandArgument='<%# Container.DataItemIndex %>'..../>
dont use GridView1_RowEditing, use RowCommand (write the code in RowCommand what you have written in GridView1_RowEditing)
Refer : http://ranafaisal.wordpress.com/2008/03/31/how-to-get-the-current-row-in-gridview-row-command-event/
http://www.codeproject.com/Questions/253643/Gridview-RowCommand-event
http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.gridview.rowcommand.aspx
Karthick S
R2
Member
96 Points
96 Posts
Re: GridView Problem Framework 4.0
Nov 06, 2012 10:53 AM|LINK
Thank's!!! Problem Solve with yout Tip! ;-)