网格视图不显示单击按钮上的数据

问题描述:

我在gridview中有关于数据和按钮点击的问题

这是我的代码:

ASP:

I have problem regarding data and button click in gridview
this is my code :
ASP:

<table width="580px" cellspacing="5px" align="left">
        <tr>
            <td colspan="4">
                <asp:UpdatePanel ID="UpdatePanel1" runat="server">
                    <ContentTemplate>
                        <asp:ValidationSummary ID="ValidationSummary1" runat="server" HeaderText="Error Page :"

                            Width="100%" CssClass="validation" ShowMessageBox="True" Style="color: #FF0000"

                            Font-Names="Book Antiqua" Font-Size="10"></asp:ValidationSummary>
                    </ContentTemplate>
                </asp:UpdatePanel>
            </td>
        </tr>
        <tr>
            <td valign="top" style="font-family: 'book Antiqua'; font-size: 10pt; color: #000000"

                nowrap="nowrap" width="100px">
                File Name <font color="#FF0000" size="2">*</font>
            </td>
            <td width="10px" valign="top" style="font-family: 'book Antiqua'; font-size: 10pt;
                color: #000000">
                :
            </td>
            <td>
                <%--<asp:UpdatePanel ID="UpdatePanel4" runat="server">
                    <ContentTemplate>--%>
                <dx:ASPxUploadControl ID="filenameASPxUploadControl"  runat="server" CssFilePath="~/App_Themes/Office2010Silver/{0}/styles.css"

                    CssPostfix="Office2010Silver" Font-Names="Book Antiqua" Font-Size="10pt" Height="20px"

                    SpriteCssFilePath="~/App_Themes/Office2010Silver/{0}/sprite.css" AddUploadButtonsHorizontalPosition="Right"

                    ClientInstanceName="uploader" ShowProgressPanel="True" ForeColor="Black">
                    <ValidationSettings MaxFileSize="4000000" AllowedFileExtensions=".xls">
                    </ValidationSettings>
                </dx:ASPxUploadControl>
                <%-- </ContentTemplate>
                </asp:UpdatePanel>--%>
            </td>
            <td align="right" valign="top">
                <asp:UpdatePanel ID="UpdatePanel7" runat="server">
                    <ContentTemplate>
                        <asp:LinkButton ID="LinkButton1" runat="server">Download Template</asp:LinkButton>
                    </ContentTemplate>
                </asp:UpdatePanel>
            </td>
        </tr>
        <tr>
            <td colspan="2">
                 
            </td>
            <td colspan="2">
                <table width="100%" style="margin-removed 0px">
                    <tr>
                        <td width="80px" align="left">
                            <asp:UpdatePanel ID="UpdatePanel2" runat="server">
                                <ContentTemplate>
                                    <dx:ASPxButton ID="btnUpload"  runat="server" EnableTheming="True" Text="Add" ClientInstanceName="btnUpload"

                                        EnableDefaultAppearance="False" ImagePosition="Right" Width="78px" Height="25px"

                                        Cursor="pointer" ForeColor="Black" Font-Names="Book Antiqua" BackgroundImage-HorizontalPosition="center"

                                        BackgroundImage-VerticalPosition="top" VerticalAlign="Top" TabIndex="2" Font-Size="10pt"

                                        AutoPostBack="False">
                                        <HoverStyle ForeColor="#000000" BackgroundImage-Repeat="NoRepeat">
                                            <BackgroundImage ImageUrl="Image/btnhover.png" Repeat="NoRepeat" HorizontalPosition="center"

                                                VerticalPosition="top" />
                                        </HoverStyle>
                                        <Paddings PaddingTop="3px" />
                                        <PressedStyle ForeColor="#7C7B7B" BackgroundImage-Repeat="NoRepeat">
                                            <BackgroundImage ImageUrl="Image/hoverpress.png" Repeat="NoRepeat" HorizontalPosition="center"

                                                VerticalPosition="top" />
                                        </PressedStyle>
                                        <FocusRectBorder BorderColor="#757575" BorderStyle="Dotted" BorderWidth="2px" />
                                        <BackgroundImage ImageUrl="Image/Button.png" Repeat="NoRepeat" HorizontalPosition="center"

                                            VerticalPosition="top" />
                                        <ClientSideEvents Click="function(s, e) { uploader.UploadFile(); }" />
                                    </dx:ASPxButton>
                                </ContentTemplate>
                            </asp:UpdatePanel>
                        </td>
                        <td width="80px">
                            <dx:ASPxButton ID="btnClear"  runat="server" EnableTheming="True" Text="Clear" EnableDefaultAppearance="False"

                                ImagePosition="Right" Width="78px" Height="25px" Cursor="pointer" ForeColor="#000000"

                                Font-Names="Book Antiqua" BackgroundImage-HorizontalPosition="center" BackgroundImage-VerticalPosition="top"

                                VerticalAlign="Top" TabIndex="2" Font-Size="10pt" AutoPostBack="False">
                                <HoverStyle ForeColor="#000000" BackgroundImage-Repeat="NoRepeat">
                                    <BackgroundImage ImageUrl="Image/btnhover.png" Repeat="NoRepeat" HorizontalPosition="center"

                                        VerticalPosition="top" />
                                </HoverStyle>
                                <Paddings PaddingTop="3px" />
                                <PressedStyle ForeColor="#7C7B7B" BackgroundImage-Repeat="NoRepeat">
                                    <BackgroundImage ImageUrl="Image/hoverpress.png" Repeat="NoRepeat" HorizontalPosition="center"

                                        VerticalPosition="top" />
                                </PressedStyle>
                                <FocusRectBorder BorderColor="#757575" BorderStyle="Dotted" BorderWidth="2px" />
                                <BackgroundImage ImageUrl="Image/Button.png" Repeat="NoRepeat" HorizontalPosition="center"

                                    VerticalPosition="top" />
                            </dx:ASPxButton>
                        </td>
                        <td>
                             
                        </td>
                    </tr>
                </table>
            </td>
        </tr>
        <tr>
            <td colspan="4" style="border-top-style: solid; border-color: #979595">
                 
            </td>
        </tr>
        <tr>
            <td colspan="4">
                <asp:UpdatePanel ID="UpdatePanel3" runat="server" >
                    <ContentTemplate>
                        <dx:ASPxGridView ID="grdData"  runat="server" AutoGenerateColumns="True" CssFilePath="~/App_Themes/Office2010Silver/{0}/styles.css"

                            CssPostfix="Office2010Silver" Width="100%" KeyFieldName="SN"  önRowDeleting="grdData_RowDeleting">
                            <Columns>
                                <dx:GridViewDataTextColumn VisibleIndex="0" Caption="No" Width="40px" ReadOnly="True"

                                    HeaderStyle-HorizontalAlign
								

\", connectionString)
adapter.Fill(dataTable)
Dim FileToDelete As String
'Set full path to file
FileToDelete = Server.MapPath(UploadDirectory) + Session( \"UserNam\") + \".xls\"
'Delete a file
File.Delete(FileToDelete)
Return dataTable
Catch ex As Exception
Throw New Exception(String.Format(\"File error ! {0}Please check your file, make sure use default template.\", vbCrLf))
Me.cvalPageError.IsValid = False
Me.cvalPageError.ErrorMessage = ex.Message
Return dataTable
End Try
End Function

Private Function SavePostedFiles(ByVal uploadedFile As UploadedFile) As String
Try
If (Not uploadedFile.IsValid) Then
Return String.Empty
End If

Dim fileInfo As New FileInfo(uploadedFile.FileName)
Dim newFileName As String
'x = Replace(file.Name, file.Name, \"ishaq\")
newFileName = fileInfo.Name.Replace(fileInfo.Name, Session(\"UserNam\"))
Session(\"FileName\") = fileInfo.Name
Dim resFileName As String = Server.MapPath(UploadDirectory) + newFileName + \".xls\"
uploadedFile.SaveAs(resFileName)

Return resFileName
Catch ex As Exception
Me.cvalPageError.IsValid = False
Me.cvalPageError.ErrorMessage = ex.Message
End Try

End Function

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Try
If Session(\"wasLogin\") <> \"Login\" Then
Response.Redirect(\"~/Login.aspx\", False)
Exit Sub
End If
Dim sl As New SSaveLog
Dim dts As New SServerInformation
sl.SaveLog(Session(\"CountryCode\"), Session(\"UserNam\"), dts.GetServerTime)
If (Not IsPostBack) Then
ClearPageSession()
BindTable()
If Session(\"BPType\") = \"T1\" Then
'UpdatePanel3.Update()
grdData.DataSource = Session(\"FillGrid\")
grdData.DataBind()
End If
Else
If Session(\"BPType\") = \"T1\" Then
grdData.DataSource = Session(\"DT_DataTable_T1SO_ByFile\")
grdData.DataBind()
End If
End If
'Session(\"FillGrid\") = Nothing
Session(\"FillGrid\") = Nothing
Catch ex As Exception
Me.cvalPageError.IsValid = False
Me.cvalPageError.ErrorMessage = ex.Message
End Try
End Sub

Protected Sub filenameASPxUploadControl_FileUploadComplete1(ByVal sender As Object, ByVal e As DevExpress.Web.ASPxUploadControl.FileUploadCompleteEventArgs) Handles filenameASPxUploadControl.FileUploadComplete
Try
FillGridFroExcel(OpenExcelFile(SavePostedFiles(e.UploadedFile)))
'Respons e.Redirect(\"~/T_T1SO_ByFile.aspx\", False)
'e.CallbackData = Session(\"DT_DataTable_T1SO_ByFile\")
Catch ex As Exception
Me.cvalPageError.IsValid = False
Me.cvalPageError.ErrorMessage = ex.Message
End Try
End Sub

Protected Sub btnUpload_Click(ByVal sender As Object, ByVal e As Syste m.EventArgs) Handles btnUpload.Click
grdData.DataSource = Session(\"DT_DataTable_T1SO_ByFile\")
grdData.DataBind()
End Sub
", connectionString) adapter.Fill(dataTable) Dim FileToDelete As String 'Set full path to file FileToDelete = Server.MapPath(UploadDirectory) + Session("UserNam") + ".xls" 'Delete a file File.Delete(FileToDelete) Return dataTable Catch ex As Exception Throw New Exception(String.Format("File error ! {0}Please check your file, make sure use default template.", vbCrLf)) Me.cvalPageError.IsValid = False Me.cvalPageError.ErrorMessage = ex.Message Return dataTable End Try End Function Private Function SavePostedFiles(ByVal uploadedFile As UploadedFile) As String Try If (Not uploadedFile.IsValid) Then Return String.Empty End If Dim fileInfo As New FileInfo(uploadedFile.FileName) Dim newFileName As String 'x = Replace(file.Name, file.Name, "ishaq") newFileName = fileInfo.Name.Replace(fileInfo.Name, Session("UserNam")) Session("FileName") = fileInfo.Name Dim resFileName As String = Server.MapPath(UploadDirectory) + newFileName + ".xls" uploadedFile.SaveAs(resFileName) Return resFileName Catch ex As Exception Me.cvalPageError.IsValid = False Me.cvalPageError.ErrorMessage = ex.Message End Try End Function Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load Try If Session("wasLogin") <> "Login" Then Response.Redirect("~/Login.aspx", False) Exit Sub End If Dim sl As New SSaveLog Dim dts As New SServerInformation sl.SaveLog(Session("CountryCode"), Session("UserNam"), dts.GetServerTime) If (Not IsPostBack) Then ClearPageSession() BindTable() If Session("BPType") = "T1" Then 'UpdatePanel3.Update() grdData.DataSource = Session("FillGrid") grdData.DataBind() End If Else If Session("BPType") = "T1" Then grdData.DataSource = Session("DT_DataTable_T1SO_ByFile") grdData.DataBind() End If End If 'Session("FillGrid") = Nothing Session("FillGrid") = Nothing Catch ex As Exception Me.cvalPageError.IsValid = False Me.cvalPageError.ErrorMessage = ex.Message End Try End Sub Protected Sub filenameASPxUploadControl_FileUploadComplete1(ByVal sender As Object, ByVal e As DevExpress.Web.ASPxUploadControl.FileUploadCompleteEventArgs) Handles filenameASPxUploadControl.FileUploadComplete Try FillGridFroExcel(OpenExcelFile(SavePostedFiles(e.UploadedFile))) 'Response.Redirect("~/T_T1SO_ByFile.aspx", False) 'e.CallbackData = Session("DT_DataTable_T1SO_ByFile") Catch ex As Exception Me.cvalPageError.IsValid = False Me.cvalPageError.ErrorMessage = ex.Message End Try End Sub Protected Sub btnUpload_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnUpload.Click grdData.DataSource = Session("DT_DataTable_T1SO_ByFile") grdData.DataBind() End Sub







Please help me,

Gridview isnot showing data on single click of \"upload\" button, but if I click again \"upload\" button gridview will be showing data.




Please help me,
Gridview isnot showing data on single click of "upload" button, but if I click again "upload" button gridview will be showing data.


you can use updatepanel updatemode as conditional.

http://www.aspdotnet-suresh.com/2012/05/ajax-updapanel-control-with-triggers.html[^]



or you can use timer events.

http://msdn.microsoft.com/en-us/library/cc295400.aspx[^]
you can use updatepanel updatemode as conditional.
http://www.aspdotnet-suresh.com/2012/05/ajax-updapanel-control-with-triggers.html[^]

or you can use timer events.
http://msdn.microsoft.com/en-us/library/cc295400.aspx[^]


Hi


Be clear with your question, what is the requirement you want to achieve what type of trouble you are facing. Just comment the update panel and try the code.

On a button click you want to bring the data from Database and bind that to the grid view? is this your intention?
Hi
Be clear with your question, what is the requirement you want to achieve what type of trouble you are facing. Just comment the update panel and try the code.
On a button click you want to bring the data from Database and bind that to the grid view? is this your intention?