如何在asp.net(c#)的gridview中的label.text中显示特定的单元格数据 [英] how to display spesific cell data in label.text in gridview in asp.net(c#)

查看:89
本文介绍了如何在asp.net(c#)的gridview中的label.text中显示特定的单元格数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨每一个

我有asp.net c#网站我在我的表格上:

1. sqldatasource1

2.gridview1

3.textbox1(输入一年)和dropdownlist1(选择一个月)

4.textbox2(输入一年)和dropdownlist2(选择一个月)

5.两个标签

6.我想在选择月份和年份时,gridview1中的具体数据显示在label1和label2中

7然后我要计算那些数据,例如+或*或......

8.我在vb.net中这样做我获取数据的代码是:



hi every one
I have asp.net c# website I have on my form:
1. sqldatasource1
2.gridview1
3.textbox1(for input a year) and dropdownlist1(for select a month)
4.textbox2(for input a year) and dropdownlist2(for select a month)
5.two label
6.I want when I select a month and year, the specific data in gridview1 display in label1 and label2
7.then I want to calculate that data e.g "+" or "*" or ...
8. I do this in vb.net my code for get data is :

 Public Sub get_data1()
            cn.Open()
            Dim dt As New DataTable("shakhes")
            Dim rs As New SqlDataAdapter("select * from shakhes where sal_tadieh = '" & TextBoxX4.Text & "' and mah_tadieh = '" & ComboBoxEx3.Text & "'", cn)
            rs.Fill(dt)
            ShakhesDataGridView.DataSource = dt
            ShakhesDataGridView.Refresh()
            Label1.Text = dt.Rows.Count
            rs.Dispose()
            cn.Close()
            If Val(Label1.Text) = 1 Then
                Dim i As Integer
                i = ShakhesDataGridView.CurrentRow.Index
                TextBoxX2.Text = ShakhesDataGridView.Item(2, i).Value
            ElseIf Val(Label1.Text) = 0 Then
                TextBoxX2.Text = "there is no data"
            End If
        End Sub
        Public Sub get_data2()
            cn.Open()
            Dim dt As New DataTable("shakhes")
            Dim rs As New SqlDataAdapter("select * from shakhes where sal_tadieh = '" & TextBoxX5.Text & "' and mah_tadieh = '" & ComboBoxEx4.Text & "'", cn)
            rs.Fill(dt)
            ShakhesDataGridView.DataSource = dt
            ShakhesDataGridView.Refresh()
            Label1.Text = dt.Rows.Count
            rs.Dispose()
            cn.Close()
            If Val(Label1.Text) = 1 Then
                Dim i As Integer
                i = ShakhesDataGridView.CurrentRow.Index
                TextBoxX3.Text = ShakhesDataGridView.Item(2, i).Value
                 ElseIf Val(Label1.Text) = 0 Then
                TextBoxX3.Text = "there is no data"
            End If
        End Sub


9. my code for calculate data:



     Public Sub boro()
            Dim a As Decimal
            Dim b, c As Decimal
            Dim fo_labl As Decimal
            a = TextBoxX1.Text
            b = Val(TextBoxX2.Text)
            c = Val(TextBoxX3.Text)
            If b = 0 Or c = 0 Then
                MessageBox.Show("no data", "notice", MessageBoxButtons.OK, MessageBoxIcon.Information)
            Else
                LabelX5.Text = (c / b) * a
            End If
            fo_labl = Val(LabelX5.Text)
            LabelX5.Text = FormatNumber(fo_labl, NumDigitsAfterDecimal:=0, GroupDigits:=TriState.True)
        End Sub
        Private Sub tadieh_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
            'TODO: This line of code loads data into the 'Ejra_dbDataSet.shakhes' table. You can move, or remove it, as needed.
            Me.ShakhesTableAdapter.Fill(Me.Ejra_dbDataSet.shakhes)
            expo()
            display_data()
        End Sub
        Private Sub ComboBoxEx3_SelectedIndexChanged_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ComboBoxEx3.SelectedIndexChanged
            get_data1()
            LabelX6.Text = TextBoxX2.Text
        End Sub

        Private Sub ComboBoxEx4_SelectedIndexChanged_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ComboBoxEx4.SelectedIndexChanged
            get_data2()
            LabelX7.Text = TextBoxX3.Text
        End Sub
        Private Sub ButtonX3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ButtonX3.Click
            Me.Close()
        End Sub

        Private Sub TextBoxX1_KeyPress1(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles TextBoxX1.KeyPress
            e.Handled = Not ((Asc(e.KeyChar) >= 48 And Asc(e.KeyChar) <= 57) Or Asc(e.KeyChar) = 8)
        End Sub

        Private Sub TextBoxX1_TextChanged_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBoxX1.TextChanged
            Try
                TextBoxX1.Text = Format(CULng(TextBoxX1.Text), "#,#")
                TextBoxX1.SelectionStart = TextBoxX1.Text.Length
            Catch ex As Exception

            End Try
        End Sub

        Private Sub ShakhesBindingNavigatorSaveItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
            Me.Validate()
            Me.ShakhesBindingSource.EndEdit()
            Me.TableAdapterManager.UpdateAll(Me.Ejra_dbDataSet)
        End Sub

        Private Sub TextBoxX4_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBoxX4.TextChanged
            get_data1()
            LabelX6.Text = TextBoxX2.Text
        End Sub

        Private Sub TextBoxX5_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBoxX5.TextChanged
            get_data2()
            LabelX7.Text = TextBoxX3.Text
        End Sub


        Private Sub ButtonX1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ButtonX1.Click
            If TextBoxX1.Text = "" Then
                MessageBox.Show("please fill", "notice", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
            ElseIf TextBoxX4.Text = "" Then
                MessageBox.Show("please fill", "notice", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
            ElseIf TextBoxX5.Text = "" Then
                MessageBox.Show("please fill", "notice", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
            ElseIf ComboBoxEx3.Text = "" Then
                MessageBox.Show("please fill", "notice", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
            ElseIf ComboBoxEx4.Text = "" Then
                MessageBox.Show("please fill", "notice", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
           Else
                boro()
            End If
        End Sub
    End Class

10. now I want do same thing for asp.net but my problem is that gridview dose not have same property e.g 
 i = ShakhesDataGridView.CurrentRow.Index
                TextBoxX2.Text = ShakhesDataGridView.Item(2, i).Value


11.by the way i know about asp.net and c# a liitle and i am an amateur

推荐答案

我认为您正在寻找 GridView.SelectedIndexChanged事件 [ ^ ]。

I think you are looking for GridView.SelectedIndexChanged Event[^].
// Get the currently selected row using the SelectedRow property.
GridViewRow row = CustomersGridView.SelectedRow;


这篇关于如何在asp.net(c#)的gridview中的label.text中显示特定的单元格数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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