hi,

I have a Gridview like below:

What I want is:
1) User can click at LINE column, for example user click at M23 and it will redirect to other page.
2) At the other page, it will display something like this:
Please insert countermeasure for M23

where M23 is get from what user click.

How can I do that?

Here is my code:

Dim DBConn As New SqlConnection("server=xxxx;uid=xxxx;pwd=xxxx;database=xxxx")
            Dim DBCmd As New SqlCommand
            Dim da As New SqlDataAdapter
            Dim ds As New DataSet()
            Dim strtTime As String
            Dim endTime As String

            strtTime = DateTime.Today.ToString("yyyy/MM/dd") & " " & "06:15:00"
            endTime = DateTime.Today.ToString("yyyy/MM/dd") & " " & "18:15:00"

            Try
                DBConn.Open()

                Dim SQLstr As String = " SELECT   LINE, SUM(KYUERR1 + VISION1 + KEIJYOU1) AS PICKUP_ERR, SUM((KYUERR1 + VISION1 + KEIJYOU1) * UNITCOST) AS RM "
                SQLstr &= " FROM         VAC_JSINFO "
                SQLstr &= " WHERE       (COLLECTDATE > '" & strtTime & "') AND (COLLECTDATE < '" & endTime & "') AND (KYUERR1 >= 0) "
                SQLstr &= " GROUP BY LINE "
                SQLstr &= " ORDER BY RM DESC "

                Dim myCommand As New SqlCommand(SQLstr, DBConn)
                da.SelectCommand = myCommand
                da.Fill(ds)

                GridView1.DataSource = ds
                GridView1.DataBind()

Recommended Answers

All 6 Replies

You haven't said if you are having a problem with

  • determining which cell was clicked
  • determining the value in that cell
  • calling another form
  • passing a value to that form

In the CellClick event handler of the DataGridView you can determine the row and column clicked by

e.RowIndex and e.ColumnIndex

You can get the value by

Dim grd As DataGridView = sender
MsgBox(grd(e.ColumnIndex,e.RowIndex).Value)

Use that value when the new form is displayed.

Hi Reverend Jim! Thank you for your reply.

Actually, I dont know where to start first since I'm still new in programming world and this is the first time i'm trying to manipulate gridview.

May I know where can I add the cellClick event handler in the code that i provided above?

May I know where can I add the cellClick event handler in the code that i provided above?

Select the DataGridView control in design view. Go to the events tab of the properties and double click CellContentClick. An empty event handler will be added to your code that you can modify as needed.

I did some changes in datagridview properties like below:

 <Columns>
 <asp:HyperLinkColumn DataNavigateUrlField="LINE" DataTextField="LINE" 
                    HeaderText="LINE" DataNavigateUrlFormatString="Dust.aspx?Line={0}" Target="_blank">
                </asp:HyperLinkColumn>

and the result, i got it works like below:
hyperlinkOk

Now, how can I get what LINE did i choose, for example i click at M23 to appear in the second page?

This is the example output that I want, place somewhere in the second page:

CNTRM

where the M23 got from 1st page that user click.

Thank you :)

Alright.. I got what I want.. hehe.. Thank you very much :)

Anyway, here is the code in second page:

<div>

        Please Insert Countermeasure for Line&nbsp;
        <asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>

    </div>

And this is the code behind in the second page:

Label1.Text = Request.QueryString("LINE")

Thank you very much! (^_^)

if I have The same Problem In vb.net then what should I do????????????????.......plz reply

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.