Click here to Skip to main content
15,893,622 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have
VB
 Partial Class _Default
    Inherits System.Web.UI.Page
    Dim objCls As New CommClass
    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

    End Sub
    Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim str As String = "Select SrNo,Name From Mst_Login order by Name"
        Dim ds As New DataSet()
        ds = objCls.GetDs(str)
        GridView1.DataSource = ds.Tables(0)
        GridView1.DataBind()
    End Sub
    Protected Sub GridView1_RowCommand(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewCommandEventArgs) Handles GridView1.RowCommand
        txt1.Text = e.CommandArgument
    End Sub
    Protected Sub GridView1_RowDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles GridView1.RowDataBound
        Try

            If e.Row.RowType = DataControlRowType.DataRow Then
                Dim LnkTest As New LinkButton()
                LnkTest.ID = "myID"
                LnkTest.CommandArgument = e.Row.Cells(0).Text
                LnkTest.Text = e.Row.Cells(0).Text
                AddHandler LnkTest.Click, AddressOf GridView1_RowCommand
                e.Row.Cells(0).Controls.Add(LnkTest)
            End If
        Catch ex As Exception

        End Try
    End Sub
End Class


i want my cloumn SrNo as linkbutton... this code convert Srno to linkbutton for first time run when i click link button Row_Command not firing and also linkbutton doesn't remain
any sollution or suggestions????
Thanks in Advance...!!!
Posted

1 solution

hi Dear,

1. Only numeric name is not allowed as a control/variable name.
you have to set prefix befor your srno field.

Please not that your variable name or your control name must not start with number.
Ex; variable name or control name like 123 is not allowed. insted of it you have to give prefix like _123 or lbtn123

like "lbtn" +[SrNo]

see more example:

a. 123lbtn ----------- not valid
b. 123 ----------- not valid
c. lbtn123 ----------- valid
d. _123 ----------- valid

2. you have to bind KeyValueField to GridView from asp/aspx page.
 
Share this answer
 
Comments
Devang Vaja 6-Nov-12 6:53am    
excuse me Boss this is not what i want my code doesn't give me any error in my code i have dynamically given linkbutton id but it's row_Command is not firing...and if i am not getting row_COmmand event then if i have paseed keyvalue field it will not help me.. plz read my question carefully and apply in your system first....
Mr. Mahesh Patel 23-Nov-12 9:07am    
dear, your srno column is as integer, so runtime it may bug in coding but not give error. I have faced this problem as early. If you wanna try my suggestion then you can else as you wish.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900