Why can't I programatically set the value on my hidden field on a repeater?
I've had this strange proble开发者_如何学运维m come up. I have a RowDataBound
event handler for a repeater control.
I have the code:
HiddenField hfIpAddressRangeId = (HiddenField)e.Row.FindControl("hfIpAddressRangeId");
hfIpAddressRangeId.Value = .IpAddressRangeId.ToString();
But when I look at the html the value of that control is not set. However when I set the value using inline C# such as
<asp:HiddenField runat="server" Value='<%# Eval("IpAddressRangeId ") %>' ID="hfIpAddressRangeId" ViewStateMode="Enabled" />
The value is being set. I'm not really sure why this won't work when I bind each datarow?
It looks like IpAddressRangeId
is a part of your datasource, hence the use of Eval
in the second example. Have you tried this?:
HiddenField hfIpAddressRangeId = (HiddenField)e.Row.FindControl("hfIpAddressRangeId");
hfIpAddressRangeId.Value = DataBinder.Eval(e.Row.DataItem, "IpAddressRangeId").ToString();
精彩评论