我有一个带有ItemTemplate的asp:FormView.我想在FormView中使用一些div元素设计内容:
<asp:FormView ID="MyFormView" runat="server" >
<ItemTemplate>
<div class="block1">
Stuff...
</div>
<div class="block2">
Stuff...
</div>
...
<div class="blockN">
Stuff...
</div>
</ItemTemplate>
</asp:FormView>
Run Code Online (Sandbox Code Playgroud)
当我运行应用程序时,会创建以下HTML:
<table id="MyFormView" style="border-collapse: collapse;" border="0" cellspacing="0">
<tbody>
<tr>
<td colspan="2">
<div class="block1">
Stuff...
</div>
<div class="block2">
Stuff...
</div>
...
<div class="blockN">
Stuff...
</div>
</td>
</tr>
</tbody>
</table>
Run Code Online (Sandbox Code Playgroud)
实际上桌子有点令人不安.我不知道让ItemTemplate自由设置内容然后将其包装到表中的目的是什么.
是否可以禁用或解决此问题?(我在FormView属性中找不到标志.)
我最近遇到了FormView的问题,并发现使用get_form_kwargs的方法就是这样做.
这是我的代码:
class InternalResetPasswordView(FormView):
template_name = 'reset_password.html'
form_class = forms.InternalPasswordResetForm
# success_message = "Password was reset successfully"
# To get request object
# http://notesondjango.wordpress.com/2012/12/18/modelform-formview-and-the-request-object/
# https://stackoverflow.com/questions/13383381/show-message-after-password-change
# http://pydanny.com/simple-django-email-form-using-cbv.html
# http://bubuzzz.wordpress.com/2012/05/01/class-based-generic-views-in-django-a-simple-sample/
def get_form_kwargs(self):
kwargs = super(InternalResetPasswordView, self).get_form_kwargs()
kwargs['user'] = self.request.user
return kwargs
def get_success_url(self):
return reverse('user-detail', kwargs={'pk': self.request.user.id})
@method_decorator(login_required)
def dispatch(self, *args, **kwargs):
return super(InternalResetPasswordView, self).dispatch(*args, **kwargs)
'''
def get_context_data(self, **kwargs):
context = super(InternalResetPasswordView, self).get_context_data(**kwargs)
context['InternalPasswordResetForm'] = context.get('form')
return context
def get_form_kwargs(self):
kwargs = super(InternalResetPasswordView, self).get_form_kwargs()
kwargs['request'] = self.request
return kwargs …Run Code Online (Sandbox Code Playgroud) 定义FormView派生类时:
class PrefsView(FormView):
template_name = "prefs.html"
form_class = MyForm # What's wrong with this?
def get(self,request):
context = self.get_context_data()
context['pagetitle'] = 'My special Title'
context['form'] = MyForm # Why Do I have to write this?
return render(self.request,self.template_name,context)
Run Code Online (Sandbox Code Playgroud)
我预计context['form'] = MyForm不需要该行,因为form_class已定义,但没有它{{ form }}不会传递给模板.
我做错了什么?
在调试我正在处理的网站时,我得到了一个"黄色死亡屏幕".错误消息是"值不能为null.参数名称:键".我正在尝试将formview绑定到gridview的选定索引.当我在selectedindexchanged方法中设置断点时,所有内容似乎都正确绑定,我可以查看我的formview的值,但是当我继续运行它时,我收到上面的错误消息.我已经尝试将datakeynames属性添加到formview并获取相同的错误消息.我在这里搜索并谷歌并看到一些结果,但没有一个似乎修复或与我的问题有关.
一些代码如下:
protected void GridView1_SelectedIndexChanged(object sender, EventArgs e)
{
lblMessage.Text = "";
cbCalled.Visible = true;
cbError.Visible = true;
cbVerbal.Visible = true;
btnSubmit.Visible = true;
FormView1.Visible = true;
FormView1.DataBind();
FormView fv1 = FormView1;
Label PathCountLabel = (Label)fv1.FindControl("pathcountLabel");
TextBox PathResult = (TextBox)fv1.FindControl("PathResultLabel");
if ((PathCountLabel.Text != "1 of 1 biopsies") && (PathCountLabel.Text != "Only 1 Pathology Ordered"))
{
PathResult.BackColor = ColorTranslator.FromHtml("#FFFFAA");
}
}
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False"
Visible="False" DataKeyNames="PatientID" DataSourceID="SqlDataSource1"
onselectedindexchanged="GridView1_SelectedIndexChanged" AllowSorting="True" onsorting="GridView1_Sorting">
<Columns>
<asp:CommandField ShowSelectButton="True" />
<asp:BoundField DataField="PatientID" HeaderText="Patient Id" SortExpression="PatientID" /> …Run Code Online (Sandbox Code Playgroud) 我想将dropdownlist绑定到List<MyIem>代码后面.
<asp:DropDownList ID="listCategories" runat="server" Height="20px" CssClass="CategoryDropList" SelectedValue='<%# Bind("ParentId") %>' AutoPostBack="false" Width="300px">
Run Code Online (Sandbox Code Playgroud)
不使用ObjectDataSource!
如何将其绑定到下拉列表?在什么情况下?
也SelectedValue='<%# Bind("ParentId") %>'应该工作!(我的意思是dropdownlist绑定应该在此之前发生!)
我有FormView:
<asp:FormView ID="fvReport" runat="server" DefaultMode="ReadOnly" AllowPaging="false" OnModeChanging="fvReport_ModeChanging" DataKeyNames="id">
protected void fvReport_ModeChanging(Object sender, FormViewModeEventArgs e)
{
switch (e.NewMode)
{
case FormViewMode.Edit:
fvReport.AllowPaging = false;
break;
}
}
Run Code Online (Sandbox Code Playgroud)
在ItemTamplate中我放了LinkButton:
<asp:LinkButton ID="lbEdit" runat="server" CausesValidation="true" CommandName="Edit" CommandArgument='<%# Eval("id") %>'>?????????????</asp:LinkButton>
Run Code Online (Sandbox Code Playgroud)
当然,FormView有EditItemTemplate部分.
当我单击Button时,FormView将刷新并保持在ReadOnly状态.我究竟做错了什么?
我在FormView控件中有一个复选框和一个面板,我需要从后面的代码中访问它们,以便使用复选框来确定面板是否可见.这是我最初使用的代码,但由于我将控件放在FormView中,它不再有效.
Protected Sub checkGenEd_CheckedChanged(ByVal sender As Object, _
ByVal e As System.EventArgs)
If checkGenEd.Checked = True Then
panelOutcome.Visible = True
Else
panelOutcome.Visible = False
End If
End Sub
Run Code Online (Sandbox Code Playgroud)
我已经开始根据我在这里查看的其他问题来解决这个问题,但是所有问题都是在C#而不是VB中,所以这就是我所得到的:
Protected Sub FormView1_DataBound(ByVal sender As Object, ByVal e As System.EventArgs) Handles FormView1.DataBound
If FormView1.CurrentMode = FormViewMode.Edit Then
End If
End Sub
Run Code Online (Sandbox Code Playgroud)
所以,是的,我不确定如何完成它.对不起,这可能是非常基本的,但我是新来的,任何帮助都将不胜感激!
编辑:这是我现在的代码:
Protected Sub FormView1_DataBound(ByVal sender As Object, ByVal e As System.EventArgs) Handles FormView1.DataBound
If FormView1.CurrentMode = FormViewMode.Edit Then
CheckBox checkGenEd = formview1.FindControl("checkGenEd");
Panel panelOutcome = formview1.FindControl("panelOutcome");
End If
End …Run Code Online (Sandbox Code Playgroud) 我正在尝试在 Django 中实现一个 FormView,因为它似乎减少了一些样板代码。其中一个字段是文件上传字段。
class LibraryUploadLastStageForm(forms.Form):
technician = forms.ModelChoiceField(label="prepeared by" , queryset=Technician.objects.exclude(has_left=True).order_by('name') , required=True)
subprojects = forms.ModelChoiceField(label="Choose a subproject" , queryset=Subproject.objects.all().order_by('subproject_name') , required=True)
lab_tracking_excel = forms.FileField(label="Choose the Lab Tracking Excel - protocol details associated with these libraries", required=False)
Run Code Online (Sandbox Code Playgroud)
在 views.py 中,
class LibraryUploadFinalView(FormView):
template_name = 'sequencing/ChooseSomething.html'
form_class = LibraryUploadLastStageForm
def form_valid(self, form):
"""
Update the library technician, and create the librarysubproject links
"""
id_list_str = self.request.GET.get('ids')
ids = map(int , id_list_str.split(','))
libraries = Library.objects.filter(id__in=ids)
print libraries.count()
cd = form.cleaned_data
lib_kwargs …Run Code Online (Sandbox Code Playgroud) 我尝试更新FormView时出现此错误
无法在ObjectDataSource'odsForm'中的DataObjectTypeName属性指定的类型上找到名为"MainContact.FirstName"的属性.
我认为这是因为我在EditTemplate中使用了像这样的文本框
<asp:TextBox Text='<%# Bind("MainContact.FirstName") %>' ID="txtFirstName" runat="server" />
Run Code Online (Sandbox Code Playgroud)
它在文本框中显示正确的文本,但显然它在更新时不起作用.
这是FormView的数据源
<asp:ObjectDataSource ID="odsForm" runat="server" DataObjectTypeName="Helpers.BusinessObjects.EntryItem"
SelectMethod="GetEntryByEmail" TypeName="Helpers.DataAccessers.EntryHelper"
UpdateMethod="UpdateEntry">
<SelectParameters>
<asp:SessionParameter SessionField="email" Name="email" Type="String" />
</SelectParameters>
</asp:ObjectDataSource>
Run Code Online (Sandbox Code Playgroud)
这是EntryItem类
public class EntryItem
{
public int Id { get; set; }
public string Email { get; set; }
public string Password { get; set; }
public Person MainContact { get; set; }
...
}
Run Code Online (Sandbox Code Playgroud)
和人类
public class Person
{
public int Id { get; set; }
public string FirstName { get; set; …Run Code Online (Sandbox Code Playgroud) 我尝试了人类已知的每个排列,我无法在iPad的模态窗体视图中正确地调整UIWebView的大小.该网页仍然显示完整的iPad纵向宽度768点.
我在哪里以及如何告诉UIWebView显示宽度540点?
我认为'scalesPageToFit'应该这样做,但它不起作用.
我尝试将Web视图设置为窗体视图的大小,即540 x 576,带有导航和状态栏.高度是无关紧要的.
我尝试将UIWebView添加到故事板中的UIView,并调整所有大小.然后我删除了UIWebView并以编程方式添加它.
- (void)viewDidLoad
{
[super viewDidLoad];
CGRect aFrame = self.view.frame;
if (IS_IPAD)
{
aFrame = CGRectMake(0, 0, FORM_VIEW_WIDTH, FORM_VIEW_HEIGHT);
}
_webView = [[UIWebView alloc] initWithFrame:aFrame];
[_webView setOpaque:NO];
[_webView setDelegate:self];
[_webView setScalesPageToFit:YES];
self.view = _webView;
...
}
Run Code Online (Sandbox Code Playgroud)
我也尝试在viewDidAppear中加载(除了viewDidLoad,viewWillAppear等)
- (void)viewDidAppear:(BOOL)animated
{
[super viewDidAppear:animated];
[[self webView] setFrame:CGRectMake(0, 0, FORM_VIEW_WIDTH, FORM_VIEW_HEIGHT)];
[[self webView] setScalesPageToFit:YES];
NSURL *webURL = [NSURL URLWithString:@"http://www.google.com"];
NSURLRequest *request = [NSURLRequest requestWithURL:webURL cachePolicy:NSURLRequestUseProtocolCachePolicy timeoutInterval:5.0f];
[[self webView] loadRequest:request];
}
Run Code Online (Sandbox Code Playgroud)
任何建议表示赞赏
