Problem with getting cell values of gridview

  • 9 years ago

    Hi

    I jus tried to get the cell value of gridview using the following code,but it returns nothing..can anyone help me to find what goes wrong with my code

     

    Protected Sub GridView1_RowCommand(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewCommandEventArgs) Handles GridView1.RowCommand

    If e.CommandName = "Select" Then

    Dim idx As Integer = Convert.ToInt32(e.CommandArgument)

    Dim row As GridViewRow = GridView1.Rows(idx)

     

    LblDisplay.Text =
    "Customer Id: " & row.Cells(1).Text.ToString

    'End If

    End Sub

     

    Regards

    Shiji

  • 9 years ago

    hi Shiji,

    try out this:

    lblDispplay.text = gridview1.rows[idx].cells[0].text;

    this will give you the text in first cell of the selected row. instead of 0 you can specify the column no. whose value you want to get.

    Regards,

    Royal

  • 9 years ago

    Hi

     I tried this too.But am not getting the cell value.I can get upto index value.Dont know wats the problem in getting cell value...

     

  • 9 years ago

    try e.item.itemindex

     as in:

     gridview.items(e.item.itemindex).cells(0).text

    That should work.

    I made a post yesterday about client side validation with a link to my video site. As it happens, this video shows the code working too so if you have 10 minutes it is worth a watch.

    Hope this helps

    Tom.

    http://tech.kruelintent.com

  • 9 years ago

    Hi Tom,

     

    Thanks for your reply,but even this one also giving the problem

    I will be grateful if you give the complete coding inside the rowcommand event of the gridview to retrieve the cell value......

     

    Regards,

    Shiji.

     

     

  • 9 years ago

    Watch the video on my site mate, the code is shown in that.

    Failing that.... This is me grabbing a textbox (and it's contents) from a datagrid....

    Protected Sub item_click(ByVal sender As System.Object, ByVal e As DataGridCommandEventArgs)

    lblMessage.Text = ""

    If e.CommandSource.CommandName = "Clicked" Then

    If grdDemo.Items(e.Item.ItemIndex).Cells(0).Controls.Count > 0 Then

    Dim myTextBox As TextBox = grdDemo.Items(e.Item.ItemIndex).Cells(0).FindControl("txtPopMeUp")

    If Not IsNothing(myTextBox) Then

    If Trim(myTextBox.Text) <> "" Then

    lblMessage.Text = ("Message from the server side: " & vbCrLf & vbCrLf & myTextBox.Text & " must be a valid date!")

    End If

    End If

    End If

    End If

    End Sub

Post a reply

Enter your message below

Sign in or Join us (it's free).

Contribute

Why not write for us? Or you could submit an event or a user group in your area. Alternatively just tell us what you think!

Our tools

We've got automatic conversion tools to convert C# to VB.NET, VB.NET to C#. Also you can compress javascript and compress css and generate sql connection strings.

“Brevity is the soul of wit” - Shakespeare