我正在尝试查找Telerik RadGrid编辑表单中的控件。我需要能够在页面加载中执行此操作,但是我看到的大多数示例都只是在itemDataBound上,但我需要能够在页面加载时设置一个值并在按钮单击时保存一个值。
<telerik:RadGrid ID="rgNotes" runat="server" GroupPanelPosition="Top">
<GroupingSettings CollapseAllTooltip="Collapse all groups"></GroupingSettings>
<MasterTableView NoDetailRecordsText="No notes for this Appointment" AutoGenerateColumns="False" CommandItemDisplay="Top" CommandItemSettings-AddNewRecordText="Add Notes" AllowAutomaticInserts="true" EditMode="PopUp">
<Columns>
<telerik:GridEditCommandColumn UniqueName="EditCommandColumn">
</telerik:GridEditCommandColumn>
<telerik:GridBoundColumn DataField="Subject" FilterControlAltText="Filter Subject column" HeaderText="subject" ReadOnly="True" SortExpression="Subject" UniqueName="Subject">
</telerik:GridBoundColumn>
</Columns>
<EditFormSettings EditFormType="Template" InsertCaption="Add new Note">
<FormTemplate>
Subject
<p>
<telerik:RadTextBox ID="txtSubjectNotes" Width="200px" runat="server"></telerik:RadTextBox>
</p>
<p>
</p>
<telerik:RadButton ID="rdSaveNotes" OnClick="rdSaveNotes_Click" Skin="Bootstrap" BackColor="#512479" ForeColor="White" runat="server" Text="Save Notes"></telerik:RadButton>
<telerik:RadButton ID="rdCancel" OnClick="rdCancel_Click1" CommandName="Cancel" Skin="Bootstrap" BackColor="#512479" ForeColor="White" runat="server" Text="Cancel"></telerik:RadButton>
</FormTemplate>
</EditFormSettings>
</MasterTableView>
<ClientSettings>
<ClientEvents OnPopUpShowing="PopUpShowing" />
<Selecting AllowRowSelect="true" />
</ClientSettings>
</telerik:RadGrid>
作为一个例子,我试图在我的保存事件中的代码中访问它。
protected void rdSaveNotes_Click(object sender, EventArgs e)
{
try
{
int id = Convert.ToInt32(Request.QueryString["id"]);
tblApertureNetNote _note = new tblApertureNetNote();
_note.appointment_id = id;
_note.isActive = true;
_note.isDeleted = false;
_note.subject = txtSubjectNotes.Text; //It's here i can't find the textbox
_dal.Addnotes(_note);
rgNotes.DataBind();
}
catch (Exception ex)
{
logger.Error("Error in rdSaveNotes_Click function calandar edit.aspx" + ex.ToString());
}
}
答案 0 :(得分:0)
这是因为当控件放在网格中时,它们不会在设计器文件中声明为页面控件。
你必须以不同的方式掌握它们。在单击保存按钮的情况下,您应该能够获得与按钮相关的文本框。
尝试:
var button = (Control)sender; // sender is the button
// then ask the button's parent control to find the textbox
var txtSubjectNotes = button.Parent.FindControl("txtSubjectNotes") as RadTextBox;
if(txtSubjectNotes != null)
{
// make sure it's not null
_note.subject = txtSubjectNotes.Text;
}