Greetings Everyone
I am new in asp.net and i'm using RadControls for Asp.net Ajax now. I tried to follow the Asp.Net GridDemo - Insert/Update/Delete and it seems to be not all working pretty fine with me so i did few changes and turned out to be somehow doing well but the update button still not working...
I have this 2 tables tblUser and tblRole
In my Radgrid i only wanted to display the user_id,**last_name** and first_name from my tblUser and role from my tblRole
And in my Edit Form The only editable region is the last_name,first_name and role but when i hit the update Button it doesn't work.. -_-,
I'm already ok with the designs the only problem is my update button is not working..
Here's my code
TeacherRole.aspx
<telerik:RadGrid ID="RadGrid1" runat="server" AllowFilteringByColumn="True"
AllowPaging="True" AllowSorting="True"
AutoGenerateEditColumn="True" DataSourceID="SqlDataSource1" GridLines="None"
Skin="Black" DataKeyNames="user_id" EditMode="PopUp"
AllowAutomaticUpdates="True" ShowGroupPanel="True" GroupPanel-ID = "RadAjaxLoadingPanel1">
<MasterTableView EditMode="PopUp" AutoGenerateColumns="False" DataSourceID="SqlDataSource1" DataKeyNames = "user_id">
<Columns>
<telerik:GridBoundColumn DataField="user_id" DataType="System.Int32"
HeaderText="User ID" SortExpression="user_id" UniqueName="user_id">
</telerik:GridBoundColumn>
<telerik:GridBoundColumn DataField="last_name" HeaderText="Last Name"
SortExpression="last_name" UniqueName="last_name">
</telerik:GridBoundColumn>
<telerik:GridBoundColumn DataField="first_name" HeaderText="First Name"
SortExpression="first_name" UniqueName="first_name">
</telerik:GridBoundColumn>
<telerik:GridBoundColumn DataField="role"
HeaderText="Role" SortExpression="role" UniqueName="role">
</telerik:GridBoundColumn>
</Columns>
<EditFormSettings InsertCaption="Add new item" CaptionFormatString="Edit User ID: {0}"
CaptionDataField="user_id" EditFormType="Template" PopUpSettings-Modal="True" PopUpSettings-ScrollBars="Auto">
<FormTemplate>
<table id="Table1" cellspacing="1" cellpadding="1" width="250" border="0">
<tr>
<td>
User ID:
</td>
<td>
<asp:label id="Message1" runat="server" text='<%# Bind( "user_id" ) %>'/>
</td>
</tr>
<tr>
<td>
Last Name:
</td>
<td>
<asp:TextBox ID="TextBox1" runat="server" Text='<%# Bind( "last_name" ) %>'>
</asp:TextBox>
</td>
</tr>
<tr>
<td>
First Name:
</td>
<td>
<asp:TextBox ID="TextBox2" runat="server" Text='<%# Bind( "first_name") %>' TabIndex="1">
</asp:TextBox>
</td>
</tr>
<tr>
<td>
Role:
</td>
<td>
<asp:DropDownList ID="DropDownList1" runat="server" SelectedValue='<%# Bind("role") %>'
DataSource='<%# (new string() { "Admin", "Teacher", "Student"}) %>' TabIndex="7"
AppendDataBoundItems="True">
<asp:ListItem Selected="True" Text="Select" Value=""></asp:ListItem>
</asp:DropDownList>
</td>
</tr>
</table>
<table style="width: 100%">
<tr>
<td align="right" colspan="2">
<asp:Button ID="Button1" Text='<%# Iif (TypeOf Container is GridEditFormInsertItem, "Insert", "Update") %>'
runat="server" CommandName='<%# Iif (TypeOf Container is GridEditFormInsertItem, "PerformInsert", "Update") %>'>
</asp:Button>
<asp:Button ID="Button2" Text="Cancel" runat="server" CausesValidation="False" CommandName="Cancel">
</asp:Button>
</td>
</tr>
</table>
</FormTemplate>
</telerik:RadGrid>
<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="<%$ ConnectionStrings:ProLearnConnectionString %>"
SelectCommand="SELECT tblUser.user_id, tblUser.last_name, tblUser.first_name, tblRole.role FROM tblUser INNER JOIN tblRole ON tblUser.role_id = tblRole.role_id ORDER BY tblUser.user_id"
OldValuesParameterFormatString="original_{0}"
UpdateCommand="UPDATE [tblUser] SET [last_name] = ?, [first_name] = ? WHERE [user_id] = ? ">
<UpdateParameters>
<asp:Parameter Name="last_name" Type="String" />
<asp:Parameter Name="first_name" Type="String" />
<asp:Parameter Name="original_user_id" Type="Int32" />
</UpdateParameters>
</asp:SqlDataSource>
And this if my code in
TeacherRole.aspx.vb
Imports Telerik.Web.UI
Partial Class Admin_TeacherRole Inherits System.Web.UI.Page
Private Sub RadGrid1_PreRender(ByVal sender As Object, ByVal e As System.EventArgs) Handles RadGrid1.PreRender
If Not IsPostBack Then
For Each item As GridItem In RadGrid1.MasterTableView.Items
If TypeOf item Is GridEditableItem Then
Dim editableItem As GridEditableItem = CType(item, GridDataItem)
editableItem.Edit = True
End If
Next
End If
End Sub
Protected Sub RadGrid1_UpdateCommand(ByVal source As Object, ByVal e As GridCommandEventArgs)
If e.CommandName = RadGrid.UpdateCommandName Then
If TypeOf e.Item Is GridEditFormItem Then
Dim item As GridEditFormItem = DirectCast(e.Item, GridEditFormItem)
Dim id As Integer = Convert.ToInt32(item.GetDataKeyValue("user_id"))
If id <> 0 Then
Dim txtlastname As TextBox = DirectCast(item.FindControl("TextBox1"), TextBox)
Dim txtfirstname As TextBox = DirectCast(item.FindControl("TextBox5"), TextBox)
End If
End If
End If
End Sub
End Class
Any advise and suggestion would be highly sought .. Have a nice day.. Thanks in Advance