选择后行变得不可见 [英] After selection rows become not visible

查看:80
本文介绍了选择后行变得不可见的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="ReciveChallan.aspx.cs" Inherits="ReciveChallan" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>Untitled Page</title>

</head >
<body >
    <form id="form1" runat="server">
        <div>
            <asp:GridView ID="GridView1" runat="server"

                AllowPaging="True"

                DataSourceID="SqlDataSource1"

                AutoGenerateColumns="False" CellPadding="4" ForeColor="#333333">
                <AlternatingRowStyle BackColor="White" />
                <Columns>

                    <asp:TemplateField HeaderText="Select">


                        <ItemTemplate>
                            <asp:CheckBox ID="chkSelect" runat="server"

                                AutoPostBack="true"

                                OnCheckedChanged="chkSelect_CheckedChanged" />
                        </ItemTemplate>

                    </asp:TemplateField>
                    <asp:BoundField DataField="DocketNo" HeaderText="DocketNo"

                        SortExpression="ID" />

                    <asp:TemplateField HeaderText="BranchCode"

                        SortExpression="BranchCode">
                        <ItemTemplate>
                            <asp:TextBox ID="txtBranchCode" runat="server"

                                Text='<%# Bind("BranchCode") %>' ReadOnly="true"

                                ForeColor="Blue" BorderStyle="none"

                                BorderWidth="0px">
                            </asp:TextBox>
                        </ItemTemplate>
                    </asp:TemplateField>


                    <asp:TemplateField HeaderText="Date"

                        SortExpression="Date">
                        <ItemTemplate>
                            <asp:TextBox ID="txtDate" runat="server"

                                Text='<%# Bind("Date") %>'

                                ReadOnly="true" ForeColor="Blue"

                                BorderStyle="none" BorderWidth="0px">
                            </asp:TextBox>
                        </ItemTemplate>
                    </asp:TemplateField>

                     <asp:TemplateField HeaderText="Destination"

                        SortExpression="Deatination">
                        <ItemTemplate>
                            <asp:TextBox ID="Destination" runat="server"

                                Text='<%# Bind("To") %>' ReadOnly="true"

                                ForeColor="Blue" BorderStyle="none"

                                BorderWidth="0px">
                            </asp:TextBox>
                        </ItemTemplate>
                    </asp:TemplateField>


                        <asp:TemplateField HeaderText="PKTS"

                        SortExpression="PKTS">
                        <ItemTemplate>
                            <asp:TextBox ID="txtPKTS" runat="server"

                                Text='<%# Bind("PKTS") %>' ReadOnly="true"

                                ForeColor="Blue" BorderStyle="none"

                                BorderWidth="0px">
                            </asp:TextBox>
                        </ItemTemplate>
                    </asp:TemplateField>



                    <asp:TemplateField HeaderText="ActWT"

                        SortExpression="ActWt">
                        <ItemTemplate>
                            <asp:TextBox ID="txtActWt" runat="server"

                                Text='<%# Bind("ActWt") %>'

                                ReadOnly="true" ForeColor="Blue"

                                BorderStyle="none" BorderWidth="0px">
                            </asp:TextBox>
                        </ItemTemplate>
                    </asp:TemplateField>
                     <asp:TemplateField HeaderText="ChargeWt"

                        SortExpression="ChargeWt">
                        <ItemTemplate>
                            <asp:TextBox ID="txtChargeWt" runat="server"

                                Text='<%# Bind("ChargeWt") %>'

                                ReadOnly="true" ForeColor="Blue"

                                BorderStyle="none" BorderWidth="0px">
                            </asp:TextBox>
                        </ItemTemplate>
                    </asp:TemplateField>
                     <asp:TemplateField HeaderText="Mode"

                        SortExpression="Mode">
                        <ItemTemplate>
                            <asp:TextBox ID="txtMode" runat="server"

                                Text='<%# Bind("Mode") %>'

                                ReadOnly="true" ForeColor="Blue"

                                BorderStyle="none" BorderWidth="0px">
                            </asp:TextBox>
                        </ItemTemplate>
                    </asp:TemplateField>
                     <asp:TemplateField HeaderText="ChallanNo"

                        SortExpression="ChallanNo">
                        <ItemTemplate>
                            <asp:TextBox ID="txtChallanNo" runat="server"

                                Text='<%# Bind("ChallanNo") %>'

                                ReadOnly="false" ForeColor="Blue"

                                BorderStyle="none" BorderWidth="0px">
                            </asp:TextBox>
                        </ItemTemplate>
                    </asp:TemplateField>
                    <asp:TemplateField HeaderText="VehicleNo" SortExpression="VehicleNo">
                        <ItemTemplate>
                            <asp:TextBox ID="txtVehicleNo" runat="server"

                                Text='<%# Bind("VehicleNo") %>'

                                ReadOnly="False" ForeColor="Blue"

                                BorderStyle="none" BorderWidth="0px">
                            </asp:TextBox>
                        </ItemTemplate>
                    </asp:TemplateField>
                     <asp:TemplateField HeaderText="Recive Challan Date"

                        SortExpression="Recive ChallanDate">
                        <ItemTemplate>
                            <asp:TextBox ID="txtRchallanDate" runat="server"

                                Text='<%# String.Format("{0} - {1}", Eval("RchallanDate"), System.DateTime.Now.ToString()) %>'



                                ReadOnly="False" ForeColor="Blue"

                                BorderStyle="none" BorderWidth="0px">
                            </asp:TextBox>
                        </ItemTemplate>
                    </asp:TemplateField>

                     <asp:TemplateField HeaderText="Description"

                        SortExpression="Description">
                        <ItemTemplate>
                            <asp:TextBox ID="txtDescription2" runat="server"

                                Text='<%# Bind("Description2") %>'

                                ReadOnly="False" ForeColor="Blue"

                                BorderStyle="none" BorderWidth="0px">
                            </asp:TextBox>
                        </ItemTemplate>
                         </asp:TemplateField>

                </Columns>
                <EditRowStyle BackColor="#2461BF" />
                <FooterStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
                <HeaderStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
                <PagerStyle BackColor="#2461BF" ForeColor="White" HorizontalAlign="Center" />
                <RowStyle BackColor="#EFF3FB" />
                <SelectedRowStyle BackColor="#D1DDF1" Font-Bold="True" ForeColor="#333333" />
                <SortedAscendingCellStyle BackColor="#F5F7FB" />
                <SortedAscendingHeaderStyle BackColor="#6D95E1" />
                <SortedDescendingCellStyle BackColor="#E9EBEF" />
                <SortedDescendingHeaderStyle BackColor="#4870BE" />
            </asp:GridView>
            SELECT FROM
            <asp:SqlDataSource ID="SqlDataSource1" runat="server"

                ConnectionString="<%$ ConnectionStrings:amitpandeyConnectionString2 %>"

                SelectCommand="SELECT [Date], [DocketNo], [To], [PKTS], [ActWt], [ChargeWt], [Mode], [BranchCode],[ChallanNo] ,[RchallanDate],[VehicleNo], [Description2]   FROM [CreateDocket]"

                DeleteCommand="DELETE FROM product WHERE (DocketNo= @DocketNo)"

                UpdateCommand="UPDATE [CreateDocket] SET  [Date] = @Date, [To] = @Destination,
              [PKTS]=@PKTS,[BranchCode] = @BranchCode,[ActWt] = @ActWt,[ChargeWt]=@ChargeWt,[Mode]=@Mode,[ChallanNo]=@ChallanNo,[RchallanDate]=@ChallanDate,[VehicleNo]=@VehicleNo,[Description2]=@Description WHERE [DocketNo] = @DocketNo">
                <DeleteParameters>
                    <asp:Parameter Name="DocketNo" />
                </DeleteParameters>
                <UpdateParameters>
                    <asp:Parameter Name="Date" />
                    <asp:Parameter Name="Destination" />
                    <asp:Parameter Name="PKTS" />
                    <asp:Parameter Name="BranchCode" />
                    <asp:Parameter Name="ActWt" />
                    <asp:Parameter Name="ChargeWT" />
                    <asp:Parameter Name="Mode" />
                     <asp:Parameter Name="ChallanNo" />
                    <asp:Parameter Name="ChallanDate" />
                    <asp:Parameter Name="VehicleNo" />
                    <asp:Parameter Name="Description" />

                </UpdateParameters>
            </asp:SqlDataSource>
            <br />

            <asp:Button ID="btnUpdate" runat="server"

                OnClick="btnUpdate_Click" Text="Recive" /><br />


        </div>
    </form>
</body>
</html>





using System;

using System.Collections;

using System.Configuration;

using Syste m.Data;

using System.Linq;

using System.Web;

using System.Web.Security;

using System.Web.UI;

using System.Web.UI.HtmlControls;

using System.Web.UI.WebControls;

using System.Web.UI.WebControls.WebParts;

using System.Xml.Linq;

using System.Data.SqlClient;

using System.Text;



public partial class ReciveChallan : System.Web.UI.Page

{

string connStr = ConfigurationManager.ConnectionStrings[\"amitpandeyConnectionString2\"].ConnectionString;

protected void btnUpdate_Click(object sender, EventArgs e)

{

StringBuilder strSql = new StringBuilder(string.Empty);



SqlConnection con = new SqlConnection(connStr);

SqlCommand cmd = new SqlCommand();



for (int i = 0;我< GridView1.Rows.Count; i++)

{

CheckBox chkUpdate = (CheckBox)

GridView1.Rows[i].Cells[0].FindControl(\"chkSelect\");

if (chkUpdate != null)

{

if (chkUpdate.Checked)

{



string strDocketNo = GridView1.Rows[i].Cells[1].Text;



string strBranchCode = ((TextBox)GridView1.Rows[i].FindControl(\"txtBranchCode\")).Text;



string strDate = ((TextBox)GridView1.Rows[i].FindControl(\"txtDate\")).Text;



string strDestination = ((TextBox)GridView1.Rows[i].FindControl(\"Destination\")).Text;



string strPKTS = ((TextBox)GridView1.Rows[i].FindControl(\"txtPKTS\")).Text;



string strActWt = ((TextBox)GridView1.Rows[i].FindContr ol(\"txtActwt\")).Text;



string strChargeWt = ((TextBox)GridView1.Rows[i].FindControl(\"txtChargeWt\")).Text;



string strMode = ((TextBox)GridView1.Rows[i].FindControl(\"txtMode\")).Text;



string strChallanNo = ((TextBox)GridView1.Rows[i].FindControl(\"txtChallanNo\")).Text;



string strVehicleNo = ((TextBox)GridView1.Rows[i].FindControl(\"txtVehicleNo\")).Text;



string strRchallanDate = ((TextBox)GridView1.Rows[i].FindControl(\"txtRchallanDate\")).Text;



string strDescription2 = ((TextBox)GridView1.Rows[i].FindControl(\"txtDescription2\")).Text;



string strUpdate = \"Update CreateDocket set [To] = ’\" + strDestination + \"’,BranchCode = ’\" + strBranchCode + \"’, Date = ’\" + strDate + \"’, PKTS = ’\" + s trPKTS + \"’,ActWt = ’\" + strActWt + \"’,ChargeWt = ’\" + strChargeWt + \"’,Mode = ’\" + strMode + \"’,ChallanNo = ’\" + strChallanNo + \"’,VehicleNo = ’\" + strVehicleNo + \"’,RchallanDate = ’\" + strRchallanDate + \"’,Description2 = ’\" + strDescription2 + \"’ WHERE DocketNo =’\" + strDocketNo + \"’ \";

strSql.Append(strUpdate);

}

}

}

try

{

cmd.CommandType = CommandType.Text;

cmd.CommandText = strSql.ToString();

cmd.Connection = con;

con.Open();

cmd.ExecuteNonQuery();

}

catch (SqlException ex)

{

string errorMsg = \"Error in Updation\";

errorMsg += ex.Message;

throw new Exception(errorMsg);
$ b$b }

finally

{

con.Close();

}



}



protected void chkSelect_CheckedChanged

(object sender, EventArgs e)

{

CheckBox chkTest = (CheckBox)sender;

GridViewRow grdRow = (GridViewRow)chkTest.NamingContainer;



TextBox txtBranchCode = (TextBox)grdRow.FindControl(\"txtBranchCode\");



TextBox txtDate = (TextBox)grdRow.FindControl(\"txtDate\");



TextBox txtTo = (TextBox)grdRow.FindControl(\"TxtDestination\");



TextBox txtPKTS = (TextBox)grdRow.FindControl(\"txtPKTS\");



TextBox txtActWT = (TextBox)grdRow.FindControl(\"txtActWT\");



TextBox txtChargeWt = (TextBox)grdRow.FindControl(\"txtChargeWt\");
$b$ b

TextBox txtMode = (TextBox)grdRow.FindControl(\"txtMode\");



TextBox txtChallanNo = (TextBox)grdRow.FindControl(\"txtChallanNo\");



TextBox txtVehicleNo = (TextBox)grdRow.FindControl(\"txtVehicleNo\");



TextBox txtChallanDate = (TextBox)grdRow.FindControl(\"txtChallanDate\");



TextBox txtDescription = (TextBox)grdRow.FindControl(\"txtDescription\");





}

}

What I want is after I select the Check boxes and click on the Recive button . I want the selected Rows not be visible



using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Data.SqlClient;
using System.Text;

public partial class ReciveChallan : System.Web.UI.Page
{
string connStr = ConfigurationManager.ConnectionStrings["amitpandeyConnectionString2"].ConnectionString;
protected void btnUpdate_Click(object sender, EventArgs e)
{
StringBuilder strSql = new StringBuilder(string.Empty);

SqlConnection con = new SqlConnection(connStr);
SqlCommand cmd = new SqlCommand();

for (int i = 0; i < GridView1.Rows.Count; i++)
{
CheckBox chkUpdate = (CheckBox)
GridView1.Rows[i].Cells[0].FindControl("chkSelect");
if (chkUpdate != null)
{
if (chkUpdate.Checked)
{

string strDocketNo = GridView1.Rows[i].Cells[1].Text;

string strBranchCode = ((TextBox)GridView1.Rows[i].FindControl("txtBranchCode")).Text;

string strDate = ((TextBox)GridView1.Rows[i].FindControl("txtDate")).Text;

string strDestination = ((TextBox)GridView1.Rows[i].FindControl("Destination")).Text;

string strPKTS = ((TextBox)GridView1.Rows[i].FindControl("txtPKTS")).Text;

string strActWt = ((TextBox)GridView1.Rows[i].FindControl("txtActwt")).Text;

string strChargeWt = ((TextBox)GridView1.Rows[i].FindControl("txtChargeWt")).Text;

string strMode = ((TextBox)GridView1.Rows[i].FindControl("txtMode")).Text;

string strChallanNo = ((TextBox)GridView1.Rows[i].FindControl("txtChallanNo")).Text;

string strVehicleNo = ((TextBox)GridView1.Rows[i].FindControl("txtVehicleNo")).Text;

string strRchallanDate = ((TextBox)GridView1.Rows[i].FindControl("txtRchallanDate")).Text;

string strDescription2 = ((TextBox)GridView1.Rows[i].FindControl("txtDescription2")).Text;

string strUpdate = "Update CreateDocket set [To] = '" + strDestination + "',BranchCode = '" + strBranchCode + "', Date = '" + strDate + "', PKTS = '" + strPKTS + "',ActWt = '" + strActWt + "',ChargeWt = '" + strChargeWt + "',Mode = '" + strMode + "',ChallanNo = '" + strChallanNo + "',VehicleNo = '" + strVehicleNo + "',RchallanDate = '" + strRchallanDate + "',Description2 = '" + strDescription2 + "' WHERE DocketNo ='" + strDocketNo + "' ";
strSql.Append(strUpdate);
}
}
}
try
{
cmd.CommandType = CommandType.Text;
cmd.CommandText = strSql.ToString();
cmd.Connection = con;
con.Open();
cmd.ExecuteNonQuery();
}
catch (SqlException ex)
{
string errorMsg = "Error in Updation";
errorMsg += ex.Message;
throw new Exception(errorMsg);
}
finally
{
con.Close();
}

}

protected void chkSelect_CheckedChanged
(object sender, EventArgs e)
{
CheckBox chkTest = (CheckBox)sender;
GridViewRow grdRow = (GridViewRow)chkTest.NamingContainer;

TextBox txtBranchCode = (TextBox)grdRow.FindControl("txtBranchCode");

TextBox txtDate = (TextBox)grdRow.FindControl("txtDate");

TextBox txtTo = (TextBox)grdRow.FindControl("TxtDestination");

TextBox txtPKTS = (TextBox)grdRow.FindControl("txtPKTS");

TextBox txtActWT = (TextBox)grdRow.FindControl("txtActWT");

TextBox txtChargeWt = (TextBox)grdRow.FindControl("txtChargeWt");

TextBox txtMode = (TextBox)grdRow.FindControl("txtMode");

TextBox txtChallanNo = (TextBox)grdRow.FindControl("txtChallanNo");

TextBox txtVehicleNo = (TextBox)grdRow.FindControl("txtVehicleNo");

TextBox txtChallanDate = (TextBox)grdRow.FindControl("txtChallanDate");

TextBox txtDescription = (TextBox)grdRow.FindControl("txtDescription");


}
}
What I want is after I select the Check boxes and click on the Recive button . I want the selected Rows not be visible

推荐答案

ConnectionStrings:amitpandeyConnectionString2 %>\"

SelectCommand=\"SELECT [Date], [Docket No], [To], [PKTS], [ActWt], [ChargeWt], [Mode], [BranchCode],[ChallanNo] ,[RchallanDate],[VehicleNo], [Description2] FROM [CreateDocket]\"

DeleteCommand=\"DELETE FROM product WHERE (DocketNo= @DocketNo)\"

UpdateCommand=\"UPDATE [CreateDocket] SET [Date] = @Date, [To] = @Destination,
[PKTS]=@PKTS,[BranchCode] = @BranchCode,[ActWt] = @ActWt,[ChargeWt]=@ChargeWt,[Mode]=@Mode,[ChallanNo]=@ChallanNo,[RchallanDate]=@ChallanDat e,[VehicleNo]=@VehicleNo,[Description2]=@Description WHERE [DocketNo] = @DocketNo\"
>
<DeleteParameters>
<asp:Parameter Name=\"DocketNo\" />
</DeleteParameters>
<UpdateParameters>
< span class=\"code-keyword\"><asp:Parameter Name=\"Date\" />
<asp:Parameter Name=\"Destination\" />
<asp:Parameter Name=\"PKTS\" />
<asp:Parameter Name=\"BranchCode\" />
<asp:Parameter Name=\"ActWt\" />
<asp:Parameter< span class=\"code-attribute\"> Name=\"ChargeWT\" />
<asp:Parameter Name=\"Mode\" />
<asp:Parameter Name=\"ChallanNo\" />
<asp:Parameter Name=\"ChallanDate\" />
<asp:Parameter Name=\"VehicleNo\" />
<asp:Parameter Name=\"Description\" />

</UpdateParameters>
</asp:SqlDataSource>
<br />

<asp:Button ID=\"btnUpdate\" runat=\"server\"

OnClick=\"btnUpdate_Click\" T ext=\"Recive\" /><br />


</div>
</form>
</body>
</html>
ConnectionStrings:amitpandeyConnectionString2 %>" SelectCommand="SELECT [Date], [DocketNo], [To], [PKTS], [ActWt], [ChargeWt], [Mode], [BranchCode],[ChallanNo] ,[RchallanDate],[VehicleNo], [Description2] FROM [CreateDocket]" DeleteCommand="DELETE FROM product WHERE (DocketNo= @DocketNo)" UpdateCommand="UPDATE [CreateDocket] SET [Date] = @Date, [To] = @Destination, [PKTS]=@PKTS,[BranchCode] = @BranchCode,[ActWt] = @ActWt,[ChargeWt]=@ChargeWt,[Mode]=@Mode,[ChallanNo]=@ChallanNo,[RchallanDate]=@ChallanDate,[VehicleNo]=@VehicleNo,[Description2]=@Description WHERE [DocketNo] = @DocketNo"> <DeleteParameters> <asp:Parameter Name="DocketNo" /> </DeleteParameters> <UpdateParameters> <asp:Parameter Name="Date" /> <asp:Parameter Name="Destination" /> <asp:Parameter Name="PKTS" /> <asp:Parameter Name="BranchCode" /> <asp:Parameter Name="ActWt" /> <asp:Parameter Name="ChargeWT" /> <asp:Parameter Name="Mode" /> <asp:Parameter Name="ChallanNo" /> <asp:Parameter Name="ChallanDate" /> <asp:Parameter Name="VehicleNo" /> <asp:Parameter Name="Description" /> </UpdateParameters> </asp:SqlDataSource> <br /> <asp:Button ID="btnUpdate" runat="server" OnClick="btnUpdate_Click" Text="Recive" /><br /> </div> </form> </body> </html>





using System;

using System.Collections;

using System.Configuration;

using System.Data;

using System.Linq;

using System.Web;

using System.Web.Security;

using System.Web.UI;

using System.Web.UI.HtmlControls;

using System.Web.UI.WebControls;

using System.Web.UI.WebControls.WebParts;

using System.Xml.Linq;

using System.Data.SqlClient;

using System.Text;



public partial class ReciveChallan : System.Web.UI.Page

{

string connStr = ConfigurationManager.ConnectionStrings[\"amitpandeyConnectionString2\"].ConnectionString;

protected void btnUpdate_Click(object sender, EventArgs e)

{

StringBuilder strSql = new StringBuilder(string.Empty);



SqlConnection con = new SqlConnection(connStr);

SqlCommand cmd = new SqlCommand();



for (int i = 0 ;我< GridView1.Rows.Count; i++)

{

CheckBox chkUpdate = (CheckBox)

GridView1.Rows[i].Cells[0].FindControl(\"chkSelect\");

if (chkUpdate != null)

{

if (chkUpdate.Checked)

{



string strDocketNo = GridView1.Rows[i].Cells[1].Text;



string strBranchCode = ((TextBox)GridView1.Rows[i].FindControl(\"txtBranchCode\")).Text;



string strDate = ((TextBox)GridView1.Rows[i].FindControl(\"txtDate\")).Text;



string strDestination = ((TextBox)GridView1.Rows[i].FindControl(\"Destination\")).Text;



string strPKTS = ((TextBox)GridView1.Rows[i].FindControl(\"txtPKTS\")).Text;



string strActWt = ((TextBox)GridView1.Rows[i].FindContr ol(\"txtActwt\")).Text;



string strChargeWt = ((TextBox)GridView1.Rows[i].FindControl(\"txtChargeWt\")).Text;



string strMode = ((TextBox)GridView1.Rows[i].FindControl(\"txtMode\")).Text;



string strChallanNo = ((TextBox)GridView1.Rows[i].FindControl(\"txtChallanNo\")).Text;



string strVehicleNo = ((TextBox)GridView1.Rows[i].FindControl(\"txtVehicleNo\")).Text;



string strRchallanDate = ((TextBox)GridView1.Rows[i].FindControl(\"txtRchallanDate\")).Text;



string strDescription2 = ((TextBox)GridView1.Rows[i].FindControl(\"txtDescription2\")).Text;



string strUpdate = \"Update CreateDocket set [To] = ’\" + strDestination + \"’,BranchCode = ’\" + strBranchCode + \"’, Date = ’\" + strDate + \"’, PKTS = ’\" + s trPKTS + \"’,ActWt = ’\" + strActWt + \"’,ChargeWt = ’\" + strChargeWt + \"’,Mode = ’\" + strMode + \"’,ChallanNo = ’\" + strChallanNo + \"’,VehicleNo = ’\" + strVehicleNo + \"’,RchallanDate = ’\" + strRchallanDate + \"’,Description2 = ’\" + strDescription2 + \"’ WHERE DocketNo =’\" + strDocketNo + \"’ \";

strSql.Append(strUpdate);

}

}

}

try

{

cmd.CommandType = CommandType.Text;

cmd.CommandText = strSql.ToString();

cmd.Connection = con;

con.Open();

cmd.ExecuteNonQuery();

}

catch (SqlException ex)

{

string errorMsg = \"Error in Updation\";

errorMsg += ex.Message;

throw new Exception(errorMsg);
$ b$b }

finally

{

con.Close();

}



}



protected void chkSelect_CheckedChanged

(object sender, EventArgs e)

{

CheckBox chkTest = (CheckBox)sender;

GridViewRow grdRow = (GridViewRow)chkTest.NamingContainer;



TextBox txtBranchCode = (TextBox)grdRow.FindControl(\"txtBranchCode\");



TextBox txtDate = (TextBox)grdRow.FindControl(\"txtDate\");



TextBox txtTo = (TextBox)grdRow.FindControl(\"TxtDestination\");



TextBox txtPKTS = (TextBox)grdRow.FindControl(\"txtPKTS\");



TextBox txtActWT = (TextBox)grdRow.FindControl(\"txtActWT\");



TextBox txtChargeWt = (TextBox)grdRow.FindControl(\"txtChargeWt\");
$b$ b

TextBox txtMode = (TextBox)grdRow.FindControl(\"txtMode\");



TextBox txtChallanNo = (TextBox)grdRow.FindControl(\"txtChallanNo\");



TextBox txtVehicleNo = (TextBox)grdRow.FindControl(\"txtVehicleNo\");



TextBox txtChallanDate = (TextBox)grdRow.FindControl(\"txtChallanDate\");



TextBox txtDescription = (TextBox)grdRow.FindControl(\"txtDescription\");





}

}

What I want is after I select the Check boxes and click on the Recive button . I want the selected Rows not be visible



using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Data.SqlClient;
using System.Text;

public partial class ReciveChallan : System.Web.UI.Page
{
string connStr = ConfigurationManager.ConnectionStrings["amitpandeyConnectionString2"].ConnectionString;
protected void btnUpdate_Click(object sender, EventArgs e)
{
StringBuilder strSql = new StringBuilder(string.Empty);

SqlConnection con = new SqlConnection(connStr);
SqlCommand cmd = new SqlCommand();

for (int i = 0; i < GridView1.Rows.Count; i++)
{
CheckBox chkUpdate = (CheckBox)
GridView1.Rows[i].Cells[0].FindControl("chkSelect");
if (chkUpdate != null)
{
if (chkUpdate.Checked)
{

string strDocketNo = GridView1.Rows[i].Cells[1].Text;

string strBranchCode = ((TextBox)GridView1.Rows[i].FindControl("txtBranchCode")).Text;

string strDate = ((TextBox)GridView1.Rows[i].FindControl("txtDate")).Text;

string strDestination = ((TextBox)GridView1.Rows[i].FindControl("Destination")).Text;

string strPKTS = ((TextBox)GridView1.Rows[i].FindControl("txtPKTS")).Text;

string strActWt = ((TextBox)GridView1.Rows[i].FindControl("txtActwt")).Text;

string strChargeWt = ((TextBox)GridView1.Rows[i].FindControl("txtChargeWt")).Text;

string strMode = ((TextBox)GridView1.Rows[i].FindControl("txtMode")).Text;

string strChallanNo = ((TextBox)GridView1.Rows[i].FindControl("txtChallanNo")).Text;

string strVehicleNo = ((TextBox)GridView1.Rows[i].FindControl("txtVehicleNo")).Text;

string strRchallanDate = ((TextBox)GridView1.Rows[i].FindControl("txtRchallanDate")).Text;

string strDescription2 = ((TextBox)GridView1.Rows[i].FindControl("txtDescription2")).Text;

string strUpdate = "Update CreateDocket set [To] = '" + strDestination + "',BranchCode = '" + strBranchCode + "', Date = '" + strDate + "', PKTS = '" + strPKTS + "',ActWt = '" + strActWt + "',ChargeWt = '" + strChargeWt + "',Mode = '" + strMode + "',ChallanNo = '" + strChallanNo + "',VehicleNo = '" + strVehicleNo + "',RchallanDate = '" + strRchallanDate + "',Description2 = '" + strDescription2 + "' WHERE DocketNo ='" + strDocketNo + "' ";
strSql.Append(strUpdate);
}
}
}
try
{
cmd.CommandType = CommandType.Text;
cmd.CommandText = strSql.ToString();
cmd.Connection = con;
con.Open();
cmd.ExecuteNonQuery();
}
catch (SqlException ex)
{
string errorMsg = "Error in Updation";
errorMsg += ex.Message;
throw new Exception(errorMsg);
}
finally
{
con.Close();
}

}

protected void chkSelect_CheckedChanged
(object sender, EventArgs e)
{
CheckBox chkTest = (CheckBox)sender;
GridViewRow grdRow = (GridViewRow)chkTest.NamingContainer;

TextBox txtBranchCode = (TextBox)grdRow.FindControl("txtBranchCode");

TextBox txtDate = (TextBox)grdRow.FindControl("txtDate");

TextBox txtTo = (TextBox)grdRow.FindControl("TxtDestination");

TextBox txtPKTS = (TextBox)grdRow.FindControl("txtPKTS");

TextBox txtActWT = (TextBox)grdRow.FindControl("txtActWT");

TextBox txtChargeWt = (TextBox)grdRow.FindControl("txtChargeWt");

TextBox txtMode = (TextBox)grdRow.FindControl("txtMode");

TextBox txtChallanNo = (TextBox)grdRow.FindControl("txtChallanNo");

TextBox txtVehicleNo = (TextBox)grdRow.FindControl("txtVehicleNo");

TextBox txtChallanDate = (TextBox)grdRow.FindControl("txtChallanDate");

TextBox txtDescription = (TextBox)grdRow.FindControl("txtDescription");


}
}
What I want is after I select the Check boxes and click on the Recive button . I want the selected Rows not be visible


First of all, use Parameterized query to avoid SQL Injection attack.



And inside the Receive Button Click Event, loop through the Rows of GridView and check if the CheckBox is checked or not. If checked, then just hide that row by making visible false.
First of all, use Parameterized query to avoid SQL Injection attack.

And inside the Receive Button Click Event, loop through the Rows of GridView and check if the CheckBox is checked or not. If checked, then just hide that row by making visible false.


I would suggest using stored procedure.



Anyhow, change the select part to include only non-received rows (you need to add the field to mark it as received)



Inside receive button, loop throught the rows and if the row is checked

update the row in the database (mark it as received)

end loop



refresh the grid (which will exclude all marked rows as they are now marked as received)





If you don’t want to hit the database for each row, you can create single parameter from primary keys of the marked rows either as XML or plain CSV string. But then you have to have dedicated function for that update and parse the parameter.
I would suggest using stored procedure.

Anyhow, change the select part to include only non-received rows (you need to add the field to mark it as received)

Inside receive button, loop throught the rows and if the row is checked
update the row in the database (mark it as received)
end loop

refresh the grid (which will exclude all marked rows as they are now marked as received)


If you don't want to hit the database for each row, you can create single parameter from primary keys of the marked rows either as XML or plain CSV string. But then you have to have dedicated function for that update and parse the parameter.


这篇关于选择后行变得不可见的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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