如何获取默认模式为“编辑"的detailsview文本框字段值 [英] how to get the detailsview textbox field value where DefaultMode is Edit

查看:78
本文介绍了如何获取默认模式为“编辑"的detailsview文本框字段值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好..
我有一个DetailsView,其中使用MySQL数据库编辑默认模式
像:

hi all..
i Have a DetailsView Where Default mode is edit with Mysql DataBase
like:

<asp:DetailsView ID="DetailsView" runat="server" DefaultMode="Edit" Width="95%"
                                       BackColor="white" />


在调试过程中,像这样的详细信息视图
名字dave
性别男
22岁
状态有效
在这里,我需要更新一些值,以便在每个文本"框中写一些内容,然后单击更新"按钮.在这里,我需要获取书面值,所以我使用了Like
DetailsView1.Rows [0] .Cells [1] .Text但返回" Null值
所以如何获取新输入的值
任何人都可以帮我吗
在此先感谢


While Debugging am getting Details View Like This
name dave
Gender Male
Age 22
Status Active
here I need To update Some Values So that I write something in Every Text box And Click Update Button Here I need Get The Written Values So I used Like
DetailsView1.Rows[0].Cells[1].Text But It returns "" Null Value
so How Can I Get Newly Entered Values
Can Any One Help Me Please
Thanks In Advance

推荐答案

TextBox tb = DetailsView1.Rows[0].Cells[1].Controls[0] as TextBox;
//tb.Text is your result


采用如下所示的模板字段

Take Template Field Like Below

<asp:DetailsView ID="dvCategory" runat="server" AutoGenerateRows="False"

              DataKeyNames="iCategoryID" Width="90%" GridLines="None"

              OnItemInserting="dvCategory_ItemInserting"

              OnItemUpdating="dvCategory_ItemUpdating"

              OnModeChanging="dvCategory_ModeChanging" ondatabound="dvCategory_DataBound" >
             <Fields>
                 <asp:BoundField DataField="iCategoryID" HeaderText="ID" InsertVisible="False" ReadOnly="True" />
                 <asp:TemplateField HeaderText="Name">
                      <EditItemTemplate>
                        <asp:TextBox ID="txtCategoryName" runat="server" Text='<%# Bind("strCategoryName") %>'></asp:TextBox>
                        <asp:RequiredFieldValidator ID="rfvCategoryName" runat="server" ControlToValidate="txtCategoryName"

                        Display="Dynamic" ErrorMessage="Name" SetFocusOnError="True">*</asp:RequiredFieldValidator>
                      </EditItemTemplate>
                      <InsertItemTemplate>
                         <asp:TextBox ID="txtCategoryName" runat="server" Text='<%# Bind("strCategoryName") %>'></asp:TextBox>
                         <asp:RequiredFieldValidator ID="rfvCategoryName" runat="server" ControlToValidate="txtCategoryName"

                          Display="Dynamic" ErrorMessage="Name" SetFocusOnError="True">*</asp:RequiredFieldValidator>
                      </InsertItemTemplate>
                      <ItemTemplate>
                          <asp:Label ID="lblCategoryName" runat="server" Text='<%# Bind("strCategoryName") %>'></asp:Label>
                     </ItemTemplate>
                  </asp:TemplateField>

                 <asp:CommandField ShowEditButton="True" ShowInsertButton="True" />
                  </Fields>
              </asp:DetailsView>


这篇关于如何获取默认模式为“编辑"的detailsview文本框字段值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆