问题描述
我已经有关于如何做到这一点的想法,但我意识到,控制ControlParameter没有一个id属性(这是需要的JS)。有没有办法使用JavaScript来改变默认值属性,而不需要使用ID属性的不同的方式?
下面是JavaScript和asp.net code,我一直努力着:
JavaScript的:
函数ChangePropertyValue(propertyName的,newpropertyValue){
VAR ControlParameter =的document.getElementById(propertyName的)
ControlParameter.DefaultValue = newpropertyValue
}
asp.net:
< ASP:按钮的ID =为btnTest=服务器文本=试一试的OnClick =ChangePropertyValue(??,17)/> < ASP:SqlDataSource的ID =SqlDataSource1=服务器
的ConnectionString =下;%$的ConnectionStrings:DatabaseConnectionString1%>中
的SelectCommand =SELECT [ID],[ContentTitle],[内容] FROM [表1] WHERE([ID] = @Id)>
< SelectParameters>
< ASP:ControlParameter控件ID =ListView1的默认值=16NAME =ID
属性名=的SelectedValueTYPE =的Int32/>
< / SelectParameters>
< / ASP:SqlDataSource的>
您无法访问 ControlParameter
客户端。 ControlParameters
用于控件属性服务器端的值绑定,他们不会呈现到客户端。你可以,但是,设置的默认值 ControlParameter
编程在code的后面。
SqlDataSource1.SelectParameters [身份证] =默认值值。
I already have an idea on how to do this, but I realized that the control "ControlParameter" did not have an "Id" property (which is needed for the JS). Is there a different way to use JavaScript to change the "DefaultValue" property without the need of using the "Id" property?
Here is the JavaScript and asp.net code that I have been working with:
JavaScript:
function ChangePropertyValue(propertyName, newpropertyValue) {
var ControlParameter = document.getElementById(propertyName)
ControlParameter.DefaultValue = newpropertyValue
}
asp.net:
<asp:Button ID="btntest" runat="server" Text="try" OnClick="ChangePropertyValue(??, 17)"/>
<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="<%$ ConnectionStrings:DatabaseConnectionString1 %>"
SelectCommand="SELECT [Id], [ContentTitle], [Content] FROM [Table1] WHERE ([Id] = @Id)">
<SelectParameters>
<asp:ControlParameter ControlID="ListView1" DefaultValue="16" Name="Id"
PropertyName="SelectedValue" Type="Int32"/>
</SelectParameters>
</asp:SqlDataSource>
You can't access a ControlParameter
client side. ControlParameters
are used to bind the value of a Control property server side, they are not rendered to the client. You can, however, set the Default value of the ControlParameter
programmatically in your Code Behind.
SqlDataSource1.SelectParameters["id"].DefaultValue = "value";
这篇关于更改属性&QUOT;默认值&QUOT; ControlParameter&QUOT;在asp.net&QUOT的;使用JavaScript控制的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!