从GridView的数据库值插入 [英] Value insertion in database from GridView

查看:138
本文介绍了从GridView的数据库值插入的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在的ItemTemplate 文本框的一列复选框的一列code>在GridView和行数是动态生成。

当我点击复选框 文本框的值正在发生变化,但是当我插入值到数据库中,我在文本框正在保存的。给了默认值

 < ASP:GridView控件ID =grdData=服务器风格=文本对齐:中心;>
    <柱体和GT;
        < ASP:的TemplateField>
            <&ItemTemplate中GT;
                < ASP:复选框ID =CheckBox1=服务器的onclick =changeTextValue(本)/>
            < / ItemTemplate中>
            <&HeaderTemplate中GT;
                !< - < ASP:复选框ID =CheckBox2=服务器的OnClick =CheckAllEmp(本)/> - >
            < / HeaderTemplate中>
        < / ASP:的TemplateField>
        < ASP:的TemplateField>
            <&HeaderTemplate中GT;
                < ASP:标签ID =Status_Header=服务器文本=状态/>
            < / HeaderTemplate中>
            <&ItemTemplate中GT;
                < ASP:文本框ID =TextBox1的=服务器启用=假文本=1的ClientIDMode =静态>< / ASP:文本框>
            < / ItemTemplate中>
        < / ASP:的TemplateField>
    < /专栏>
< / ASP:GridView的>


解决方案

我找到了解决办法,删除启用=false的物业 TextBox1的和检查。

 < ASP:文本框ID =TextBox1的=服务器启用=假文字= 1的ClientIDMode =静态>< / ASP:文本框>

如果您想从最终用户禁用文本框,我建议你使用标签控制而不是 TEXTBOX

下面是标签控件的jQuery函数。

 <脚本>
功能changeTextValue(CHK){
        。VAR currentTextID = $(CHK)。家长('TR')找到('跨度[ID $ =Label1的]');
        警报(chk.checked +:+ currentTextID.text());
        如果(chk.checked ==真)
            currentTextID.text(present);
        其他
            currentTextID.text(缺席);
    }
 < / SCRIPT>

Label控件应该象下面这样:

 < ASP:标签ID =Label1的=服务器文本=缺席的EnableViewState =假的ClientIDMode =静态>< / ASP:标签&gt ;

请让我知道如果你有任何问题。

I have one column of TextBox and one column of CheckBox in ItemTemplate in a GridView and number of rows are generating dynamically.

When I click on CheckBox the value of TextBox is changing but when I am inserting the values into database, default value which I have given in TextBox it is saving that.

<asp:GridView ID="grdData" runat="server" Style="text-align: center;">
    <Columns>
        <asp:TemplateField>
            <ItemTemplate>
                <asp:CheckBox ID="CheckBox1" runat="server" onclick="changeTextValue(this)" />
            </ItemTemplate>
            <HeaderTemplate>
                <!-- <asp:CheckBox ID="CheckBox2" runat="server"OnClick="CheckAllEmp(this)" />-->
            </HeaderTemplate>
        </asp:TemplateField>
        <asp:TemplateField>
            <HeaderTemplate>
                <asp:Label ID="Status_Header" runat="server" Text="Status" />
            </HeaderTemplate>
            <ItemTemplate>
                <asp:TextBox ID="TextBox1" runat="server" Enabled="false" Text="1" ClientIDMode="Static"></asp:TextBox>
            </ItemTemplate>
        </asp:TemplateField>
    </Columns>
</asp:GridView>

解决方案

I found solution, remove Enabled="false" property from TextBox1 and check.

<asp:TextBox ID="TextBox1" runat="server" Enabled="false" Text=1 ClientIDMode="Static"></asp:TextBox>

If you want to disabled textbox from end user, I suggest you to use LABEL control instead of TEXTBOX.

Here is the jQuery function for LABEL control.

<script>
function changeTextValue(chk) {
        var currentTextID = $(chk).parents('tr').find('span[id$="Label1"]');
        alert(chk.checked + ": " + currentTextID.text());
        if (chk.checked == true)
            currentTextID.text("Present");
        else
            currentTextID.text("Absent");
    }
 </script>

Label control should be like below:

<asp:Label ID="Label1" runat="server" Text="Absent" EnableViewState="false" ClientIDMode="Static"></asp:Label>

Please let me know if you have any questions.

这篇关于从GridView的数据库值插入的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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