This is a migrated thread and some comments may be shown as answers.

autopostback onclick

6 Answers 78 Views
Grid
This is a migrated thread and some comments may be shown as answers.
appdev
Top achievements
Rank 1
appdev asked on 31 Oct 2008, 02:05 AM
i want to be able to use the itemcommand  onclick but i can't do it. here is the scenario. i have a grid declared like this in the default.aspx

<

telerik:RadGrid ID="RadGrid1" runat="server" Width="150"

 

 

 

PageSize="20" AllowSorting="True" AllowMultiRowSelection="False" Skin="Default"

 

 

 

AllowPaging="True" ShowGroupPanel="True" AutoGenerateColumns="false" GridLines="none" OnItemCommand="RadGrid1_ItemCommand">

 

 

 

</telerik:RadGrid>

then in the default.aspx.vb i have a pageload to load the data and column.

 

 

 

 

RadGrid1.DataSource = "sqlsource1"

 

 

Dim boundcolumn As GridBoundColumn

 

boundcolumn =

 

New GridBoundColumn

 

boundcolumn.DataField =

 

"Department"

 

 

 

 

boundcolumn.HeaderText =

 

"Department"

 

 

 

 

RadGrid1.MasterTableView.Columns.Add(boundcolumn)

RadGrid1.DataBind()

now i want to be able to detect a click on the row click and then open something with the column value like the Auto postback on row click example that you guys have on the web. i could detect the click but it keeps giving me error of "Index was out of range. Must be non-negative and less than the size of the collection.
Parameter name: index"
 
here is my onclick itemcommand code

 

Protected

Sub RadGrid1_ItemCommand(ByVal source As Object, ByVal e As Telerik.Web.UI.GridCommandEventArgs) Handles RadGrid1.ItemCommand

 

Thread.Sleep(2000)

 

If (e.CommandName = "RowClick" AndAlso TypeOf e.Item Is GridDataItem) Then

 

 

 

e.Item.Selected =

True

 

 

 

 

Dim text As String = "Selected mail ID is: " & e.Item.OwnerTableView.DataKeyValues(e.Item.ItemIndex)("MailID")

 

RadGrid1.Controls.Add(

New LiteralControl(String.Format("<span style='color:red'>{0}</span>", text)))

 

 

End If

 

 

 

 

End Sub

 

 

 what did i do wrong here? could you help me. thank you very much

 

 

6 Answers, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 31 Oct 2008, 03:46 AM
Hello,

I tried the fring the rowclick command on my end as shown below and it worked fine. Make sure that you have set the EnablePostBackOnRowClick property in the ClientSettings for the grid to true.
aspx:
<telerik:RadGrid ID="RadGrid2" runat="server" AllowMultiRowSelection="true"  OnItemCommand="RadGrid2_ItemCommand">              
 <MasterTableView> 
 </MasterTableView>         
  <ClientSettings EnablePostBackOnRowClick="True">                         
  </ClientSettings> 
</telerik:RadGrid> 

cs:
 protected void RadGrid2_ItemCommand(object source, GridCommandEventArgs e) 
    { 
        if (e.CommandName == "RowClick") 
        { 
 
        } 
    } 

Thanks
Princy
0
appdev
Top achievements
Rank 1
answered on 31 Oct 2008, 10:41 AM
but i can't seem to get the row_id to move on to the next part.
0
Daniel
Telerik team
answered on 31 Oct 2008, 11:01 AM
Hello Duy,

Could you please be more specific? What do you want to achieve?

Regards,
Daniel
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
0
appdev
Top achievements
Rank 1
answered on 31 Oct 2008, 11:07 AM
yes say i have 2 columns on the first grid right. studentid and name
now when i click on first row.. i want to get the studentid of that row. i could detect the row is click by using the itemcommand, but how do i get that studentid on the row i just click. thanks. i hope this is good enough for you to help me thanks.
0
appdev
Top achievements
Rank 1
answered on 31 Oct 2008, 12:31 PM
any idea guys? please help
0
appdev
Top achievements
Rank 1
answered on 31 Oct 2008, 12:59 PM
i got it. thank you
Tags
Grid
Asked by
appdev
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
appdev
Top achievements
Rank 1
Daniel
Telerik team
Share this question
or