开发者

ASP.NET DetailView InsertItemTemplate

开发者 https://www.devze.com 2023-04-02 06:25 出处:网络
I have a InsertItemTemplate defined in my DeatilView control. Within this template I have a number of fields that the user fills and a number of fields that are filled automatically and the user canno

I have a InsertItemTemplate defined in my DeatilView control. Within this template I have a number of fields that the user fills and a number of fields that are filled automatically and the user cannot change them. These values are coming from an object stored in session.

Code looks like this: (I only mention necessary parts, if you need anything more let me know)

<asp:DetailView ... DataSourceID="MyDataSource" ...>
  <Fields>
    ...
    <InsertItemTemplate>
      // These are the fields filled by the system
      <asp:Label ... Text='<%# some value from session object %>' />
      <asp:Label ... Text='<%# some value from session object %>' />
      // some textboxes here that user fills,
      //they use Bind("some data source value here") to send their data to database
      ...
    </InsertItemTemplate>
    ...
  </Fields>
</asp:DetailView>

Now the problem is where I need to actually insert values into database.

Textbox values are sent just alright, but since I haven't bound label values they are not sent to DataSource. So I'm asking how to do this?

  • An alternative I found was to pass a DefaultValue to DataSet's respective InsertParameter but I don't know how to fill that area to get it's value from Session.
  • Another alternative is to set Parameter's value (not default value) to be taken from Session, which is possible but this only support values that are directly within Session, and I'm passing the value of a property inside an object that's stored in Session. Is there a way to get this fixed, other than storing values inside 开发者_Go百科Session directly.


What type of DataSource are you using? I need to know it, because there is few ways to obtain parameters from session depending on type of datasource.


detailView_ItemInserting(object sender, DetailsViewInsertEventArgs e) is called just before inserting the data, you can use detailView.FindControl method in this event to get access to Label controls.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号