将网格视图的值存储到数据库中 [英] storing the values of grid view into database

查看:77
本文介绍了将网格视图的值存储到数据库中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的gridview中,我有sno,sname,contactnumber,subject,edit,delete和active/inactive列.在active/inactive列中,我们使用图像按钮.images来显示一个图像和非活动图像是否处于活动模式对于另一张图片.我的要求是,当我们单击活动按钮时,它将切换为不活动/不活动到活动图像,并且修改后的值将存储到数据库中.我该怎么办,有谁可以帮助我

in my gridview i have columns sno,sname,contactnumber,subject,edit,delete and active/inactive columns.In the active/inactive column we use image button .images for showing whether in the active mode for one image and inactive for another image.my requirement is when we click on active button it will chage to inactive/inactive to active images and the modified value will be stored into database.how can i do that ,can any one help me

推荐答案

参考:编辑网格视图数据 [^ ]


非常简单. GridView1_RowCommand可用于您的目的.在gridview中单击活动图像"按钮时,标识GridViewRow
Its pretty simple. GridView1_RowCommand can be used to serve your puspose. On click of Active image button in the gridview, identify the GridViewRow
<asp:gridview id="GridView1" runat="server" autogeneratecolumns="false" xmlns:asp="#unknown">
OnRowCommand = "GridView1_RowCommand">
 <columns> 
   <asp:templatefield>
        <itemtemplate>
         <asp:label runat="server" text="<%#Eval("SNo")%>" id="lblSNo" />
       </itemtemplate>
   </asp:templatefield>

   <asp:templatefield>
        <itemtemplate>
         <asp:imagebutton id="imgStatus" commandname="Update" runat="server" src="../Active.jpg" alt="Image" />
       </itemtemplate>
   </asp:templatefield>

 </columns> 

</asp:gridview>





protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
{
    int index = Convert.ToInt32(e.CommandArgument);
    GridViewRow gvRow = GridView1.Rows[index];  
    string sNo = gr.Cells[0].Text;
    bool isActive = true; // Check the image first, if it is active, set false ans send to database else set true and send to database.
    // For the above sNo. Either call stored procedure or inline query to update the database, set the status as active or inactive.
}



希望这会有所帮助.



Hope this helps.


这篇关于将网格视图的值存储到数据库中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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