I'm very new to Telerik controls and I've been reading the documentation and some of the examples but I still couldn't figure out this problem.
I'm trying to validate the address after the user entered into the textboxes and click on an image button. I have no trouble getting the values from GridBoundColumns setup for my city, state, zip. However, I can't access my address textbox in the GridTemplateColumn. Please help~
Thank you so much,
Helen
Here's is my aspx code:
<telerik:GridTemplateColumn DataField="bldgstreet1" FilterControlAltText="Filter address column" HeaderText="Address" SortExpression="address" UniqueName="addressTemplate">
<EditItemTemplate>
<asp:TextBox ID="address1" runat="server" Text='<%# Bind("bldgstreet1") %>'></asp:TextBox><br />
<asp:TextBox ID="address2" runat="server" Text='<%# Bind("bldgstreet2") %>'></asp:TextBox>
</EditItemTemplate>
<InsertItemTemplate>
<asp:TextBox ID="address1" runat="server" Text='<%# Bind("bldgstreet1") %>'></asp:TextBox><br />
<asp:TextBox ID="address2" runat="server" Text='<%# Bind("bldgstreet2") %>'></asp:TextBox>
</InsertItemTemplate>
<ItemTemplate>
<asp:Label ID="addressLabel" runat="server" Text='<%# Eval("bldgstreet1") + " " + Eval("bldgstreet2") %>'></asp:Label>
</ItemTemplate>
</telerik:GridTemplateColumn>
<telerik:GridBoundColumn DataField="bldgcity" FilterControlAltText="Filter bldgcity column" HeaderText="City" SortExpression="bldgcity" UniqueName="bldgcity">
</telerik:GridBoundColumn>
<telerik:GridBoundColumn DataField="bldgstate" FilterControlAltText="Filter bldgstate column" HeaderText="State" SortExpression="bldgstate" UniqueName="bldgstate">
</telerik:GridBoundColumn>
<telerik:GridBoundColumn DataField="bldgzip" FilterControlAltText="Filter bldgzip column" HeaderText="Zip" SortExpression="bldgzip" UniqueName="bldgzip">
</telerik:GridBoundColumn>
I tried doing this in my click event:
protected void CertifyAddressImageButton_Click(object sender, ImageClickEventArgs e)
{
foreach (GridEditableItem item in gdvBuilding.EditItems)
{
string bldgname = ((TableCell)item["bldgname"]).Text.Trim();
Debug.WriteLine("bldgname=" + bldgname);
string zip = ((TableCell)item["bldgzip"]).Text.Trim();
Debug.WriteLine("zip=" + zip);
TableCell cell = item["addressTemplate"];
string address1 = (cell.Controls[0] as TextBox).Text;
// This also doesn't work
// string address1 = (item.FindControl("address1") as TextBox).Text;
// Debug.WriteLine("address=" + address1);
Debug.WriteLine("address=" + address1);
}
//CertifyAddress();
}