Click here to Skip to main content
15,891,935 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Dear All,

I got a problem about Gridview which was contained the Data inside Detailsview. These are my code.

string ShowJobItem = "Select JobItemID, JobItemStatus, JobItemName, JobItemDes, JobOrderItems.SizeID,SizeName,JobItemQty from JobOrderItems, Sizes where JobItemID = '" + GridView2.SelectedRow.Cells[1].Text + "' AND JobOrderItems.SizeID = Sizes.SizeID ;";

DataTable dt = dbconn.QueryExecuteScalar(ShowJobItem);

GridView GV = (GridView)DetailsView1.FindControl("GridViewJobOrderItem");
GV.DataSource = dt;
GV.DataBind();


There was an error at "DataTable dt = dbconn.QueryExecuteScalar(ShowJobItem);" It show this error

Expression type int is invalid for COLLATE clause.


At first, I think it is because it cannot find the GridView, If there is UpdatePanel cover DetailView, So I tried to solve this problem by remove UpdatePanel. (It used to work well). But At this time, It s not work. So Is there any suggestions?


Thanks for your kindly help again and again.
Posted
Comments
Bandi Ramesh 13-Feb-13 6:44am    
The problem is with your select query not with your gridview or any other control; try to execute the query directly in sql server
Cmajorros 13-Feb-13 6:59am    
I have tried already and it was working with no error

1 solution

Hi,

One more important point i am teling here to you. ll be helpful for you ,while describing Columns in gridview if you are using boundfield then create objects of control using cells[index] in rowupdateing event of gridview,but if you are using controls itself like Label or textboxes etc then use Fincontrol(“stringid”).

Please check with your source code first.
 
Share this answer
 
Comments
Cmajorros 13-Feb-13 6:58am    
Actually, I have the same project in another computer . When I run this page, it works well. So Does it cause of the project's environment?
nehas1jan 13-Feb-13 7:02am    
i need to view your source code can you paste here?
Cmajorros 13-Feb-13 7:09am    
Sure!



These are for Designed Page


<%@ Page Title="" Language="C#" MasterPageFile="~/OP.Master" AutoEventWireup="true" CodeBehind="AddOrder.aspx.cs" Inherits="OPProject.Production.Order" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">
<style type="text/css">
.style9
{
width: 100%;
}
.style10
{
width: 982px;
}
.style13
{
width: 136px;
color: #FFFFFF;
}
.style20
{
width: 80px;
}
.style21
{
height: 53px;
width: 80px;
}
.style22
{
font-size: medium;
width: 982px;
}
.style23
{
width: 124px;
}
.style26
{
width: 813px;
}
.style30
{
width: 124px;
height: 21px;
}
.style31
{
width: 813px;
height: 21px;
}
.style32
{
height: 21px;
}
.style35
{
height: 31px;
}
.style49
{
width: 471px;
height: 31px;
}
.style50
{
width: 471px;
}
.style51
{
width: 124px;
height: 31px;
color: #FFFFFF;
}
.style53
{
width: 124px;
height: 30px;
}
.style54
{
width: 813px;
height: 30px;
}
.style55
{
height: 30px;
}
.style56
{
color: #696969;
}
.style63
{
width: 136px;
height: 31px;
color: #FFFFFF;
}
.style64
{
height: 31px;
color: #FFFFFF;
}
.style65
{
color: #FFFFFF;
}
.style67
{
height: 31px;
width: 813px;
}
.style68
{
width: 760px;
height: 31px;
color: #FF3300;
}
.style69
{
width: 813px;
height: 31px;
color: #FF3300;
}
</style>

<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">
 <table class="style9">
<tr>
<td class="style20">
 </td>
<td class="style10">
<asp:ScriptManager ID="ScriptManager1" runat="server">

</td>
<td>
 </td>
<td>
 </td>
</tr>
<tr>
<td class="style20">
 </td>
<td class="style22">
สร้างคำสั่งผลิต</td>
<td>
 </td>
<td>
 </td>
</tr>
<tr>
<td class="style21">
 </td>
<td colspan="3">
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<contenttemplate>
<asp:Panel ID="PanelJobOrder" runat="server" BorderColor="#666666"
BorderStyle="Solid" BorderWidth="3px" style="margin-right: 78px" Wrap="False">
<table>
<tr>
<td class="style63" bgcolor="#336699">
เลขที่คำสั่งผลิต : 
</td>
<td class="style49">
<asp:Label ID="Lbl
Cmajorros 13-Feb-13 7:10am    
These code is from Server Side

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;

namespace OPProject.Production
{
public partial class WebForm2 : System.Web.UI.Page
{
clsDatabase dbconn = new clsDatabase();
DataTable dt1;

protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
dt1 = new DataTable();
MakeDataTable();
}
else
{
dt1 = (DataTable)ViewState["DataTable"];
}
ViewState["DataTable"] = dt1;

}

protected void ImageButton1_Click(object sender, ImageClickEventArgs e)
{
String FindJobOrder = "Select * from JobOrders where JobID Like '%" + txtFindJO.Text + "%' or CusName like '%" + txtFindJO.Text + "%' and JobStatus = 'รอจัดซื้อวัตถุดิบ';";
DataTable dt = dbconn.QueryExecuteScalar(FindJobOrder);
GridView1.DataSource = dt;
GridView1.DataBind();
dbconn.Close();
PanelResult.Visible = true;
PanelAddRaw.Visible = false;
PanelDetail.Visible = false;
PanelSearch.Visible = true;
PanelOrderItem.Visible = false;
}

protected void GridView1_SelectedIndexChanged(object sender, EventArgs e)
{
string JOID = GridView1.SelectedRow.Cells[1].Text;
string SearchJI = "SELECT * FROM JobOrderItems WHERE JobID = '" + JOID + "';";
DataTable dt = dbconn.QueryExecuteScalar(SearchJI);
GridView2.DataSource = dt;
GridView2.DataBind();
dbconn.Close();
PanelOrderItem.Visible = true;
PanelResult.Visible = false;
PanelDetail.Visible = false;
PanelAddRaw.Visible = false;
PanelSearch.Visible = true;
}

protected void GridView2_SelectedIndexChanged(object sender, EventArgs e)
{
string ShowJobItem = "Select JobOrderItems.JobItemID, JobOrderItems.JobItemStatus, JobOrderItems.JobItemName, JobOrderItems.JobItemDes, JobOrderItems.SizeID,Sizes.SizeName,JobOrderItems.JobItemQty from JobOrderItems, Sizes where JobItemID = '" + GridView2.SelectedRow.Cells[1].Text + "' AND JobOrderItems.SizeID = Sizes.SizeID ;";

DataTable dt = dbconn.QueryExecuteScalar(ShowJobItem);


GridView GV = (GridView)DetailsView1.FindControl("GridViewJobOrderItem");
GV.DataSource = dt;
GV.DataBind();



string FindStyle = "SELECT dbo.JobOrders.StyleID, dbo.Styles.StylePic FROM dbo.Styles INNER JOIN dbo.JobOrders ON dbo.Styles.StyleID = dbo.JobOrders.StyleID WHERE (dbo.JobOrders.JobID = '" + GridView1.SelectedRow.Cells[1].Text + "');";
DataTable dtStyle = dbconn.QueryExecuteScalar(FindStyle);
string ImageN = dtStyle.Rows[0]["StylePic"].ToString();
string ImageName = "~/ModelPicture/" + ImageN;
Image ShowImage = (Image)DetailsView1.FindControl("Image1");
ShowImage.ImageUrl = ImageName;
dbconn.Close();
PanelDetail.Visible = true;
PanelAddRaw.Visible = true;
PanelResult.Visible = false;
PanelOrderItem.Visible = false;
PanelSearch.Visible = true;
}

protected void SqlDataSource3_Selecting(object sender, SqlDataSourceSelectingEventArgs e)
{

}

protected void BtnSave_Click(object sender, EventArgs e)
{
SaveMat();

Response.Redirect("~/Master/CompleteSave.aspx");
}
private void MakeDataTable()
{
dt1.Columns.Add("รหัสวัตถุดิบ");
dt1.Columns.Add("วัตถุดิบ");
dt1.Columns.Add("จำนวน");
dt1.Columns.Add("หน่วย");


Cmajorros 13-Feb-13 7:11am    
I am appreciated for your kindly help. Thanks again.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900