I would like to get the value of a textbox in a GridTemplateColumn. I have tried and tried to find an answer to this question. Please DO NOT refer me to any of the following:
http://www.telerik.com/help/aspnet-ajax/grdaccessingcellsandrows.html
http://demos.telerik.com/aspnet-ajax/grid/examples/programming/accessingcellsandrows/defaultcs.aspx
http://www.telerik.com/community/forums/aspnet-ajax/grid/button-click-event-and-radgrid.aspx
I have been to dozens and dozens of these links and NONE of them provide a simple, straight forward example to solve this. I have left several posts requesting similar examples with no resolution. Here is the code I am attempting to use:
ASPX:
<
telerik:RadGrid
ID
=
"rgd_ABIUser"
runat
=
"server"
GridLines
=
"None"
AutoGenerateColumns
=
"False"
Width
=
"400px"
style
=
"height: 46px"
>
<
MasterTableView
DataKeyNames
=
"ID"
>
<
RowIndicatorColumn
>
<
HeaderStyle
Width
=
"20px"
></
HeaderStyle
>
</
RowIndicatorColumn
>
<
ExpandCollapseColumn
>
<
HeaderStyle
Width
=
"20px"
></
HeaderStyle
>
</
ExpandCollapseColumn
>
<
Columns
>
<
telerik:GridTemplateColumn
DataField
=
"SC"
HeaderText
=
"Site"
SortExpression
=
"SC"
UniqueName
=
"SC"
>
<
ItemTemplate
>
<
asp:TextBox
ID
=
"tbx_Site"
Text='<%# Bind("SC") %>' runat="server" Width="30px"></
asp:TextBox
>
</
ItemTemplate
>
</
telerik:GridTemplateColumn
>
<
telerik:GridTemplateColumn
DataField
=
"ID"
HeaderText
=
"User"
SortExpression
=
"ID"
UniqueName
=
"ID"
>
<
ItemTemplate
>
<
asp:TextBox
ID
=
"tbx_UserID"
Text='<%# Bind("ID") %>' runat="server"></
asp:TextBox
>
</
ItemTemplate
>
</
telerik:GridTemplateColumn
>
<
telerik:GridTemplateColumn
DataField
=
"PW"
HeaderText
=
"Password"
SortExpression
=
"PW"
UniqueName
=
"PW"
>
<
ItemTemplate
>
<
asp:TextBox
ID
=
"tbx_Password"
Text='<%# Bind("PW") %>' runat="server"></
asp:TextBox
>
</
ItemTemplate
>
</
telerik:GridTemplateColumn
>
<
telerik:GridTemplateColumn
DataField
=
"SN"
HeaderText
=
"TCH#"
SortExpression
=
"SN"
UniqueName
=
"SN"
>
<
ItemTemplate
>
<
asp:TextBox
ID
=
"tbx_TchNo"
Text='<%# Bind("SN") %>' runat="server" Width="30px"></
asp:TextBox
>
</
ItemTemplate
>
</
telerik:GridTemplateColumn
>
<
telerik:GridTemplateColumn
DataField
=
"TG"
HeaderText
=
"Group"
SortExpression
=
"TG"
UniqueName
=
"TG"
>
<
ItemTemplate
>
<
asp:TextBox
ID
=
"tbx_TG"
Text='<%# Bind("TG") %>' runat="server" Width="20px"></
asp:TextBox
>
</
ItemTemplate
>
</
telerik:GridTemplateColumn
>
</
Columns
>
</
MasterTableView
>
</
telerik:RadGrid
>
Here is my ASPX.VB
Protected
Sub
btn_UpdateUser_Click(sender
As
Object
, e
As
System.EventArgs)
Handles
btn_UpdateUser.Click
For
Each
item
As
GridDataItem
In
rgd_ABIUser.Items
'Here is one way I have seen to get the value
Dim
txtBox
As
TextBox =
DirectCast
(item(
"PW"
).FindControl(
"tbx_Password"
), TextBox)
Dim
PW
As
String
= txtBox.Text
'Here is a different way I have seen to get the value
Dim
SN
As
String
=
DirectCast
(TryCast(item.FindControl(
"tbx_TchNo"
), TextBox).Text,
String
)
Dim
TG
As
String
=
DirectCast
(TryCast(item.FindControl(
"tbx_TG"
), TextBox).Text,
String
)
Dim
DatabaseName
As
String
= Session(
"DataBase"
)
Dim
Val = Session(
"Site"
)
Dim
Site
As
Integer
= Convert.ToInt32(Val)
Dim
IDUser
As
String
= Session(
"ID"
)
Dim
connectionString =
New
SqlConnection(
"server=DO-IT-AB\MSSQLAB;database=XXXX;UID=XXXX;PWD=XXX;"
)
Dim
command =
New
SqlCommand(
"aa_abi_users_update"
, connectionString)
command.CommandType = CommandType.StoredProcedure
command.Parameters.Add(
"@DBName"
, SqlDbType.VarChar).Value = DatabaseName
command.Parameters.Add(
"@IDSite"
, SqlDbType.Int).Value = Site
command.Parameters.Add(
"@IDUser"
, SqlDbType.VarChar).Value = IDUser
command.Parameters.Add(
"@PW"
, SqlDbType.VarChar).Value = PW
command.Parameters.Add(
"@SN"
, SqlDbType.VarChar).Value = SN
command.Parameters.Add(
"@TG"
, SqlDbType.VarChar).Value = TG
command.Connection.Open()
command.ExecuteNonQuery()
command.Connection.Close()
Next
Any help much appreciated.