关于gridview传值和excel导入到库的问题,高手门帮解决下!~
我在DataBound事件里写了点击某一行弹出窗口的代码,
但是要在弹出的这个页里获取gridview传过来的ID值,可是我在取gridview中的ID时,怎么也取不到
下面是代码;
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
e.Row.Attributes.Add( "onmouseover ", "this.style.backgroundColor= '#e7e7e7 ' ");
e.Row.Attributes.Add( "onmouseout ", "this.style.backgroundColor= 'white ' ");
}
if (e.Row.RowIndex > -1)
{
e.Row.Attributes.Add( "onclick ", "window.showModalDialog( 'test.aspx?index= "+this.GridView1.SelectedRow.RowIndex.ToString()+ " ') ");
//这行取ID值
}
}
在excel导入的时候老是提示找不到Sheet1$数据
下面是代码
string filename = this.file1.FileName;
string strCon;
strCon = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source= "+filename+ ";extended Properties=Excel 8.0; ";
OleDbConnection olecon = new OleDbConnection(strCon);
OleDbDataAdapter myda = new OleDbDataAdapter( "select * from [Sheet1$] ", strCon);
DataSet myDs = new DataSet();
myda.Fill(myDs);
if (myDs.Tables[0].Rows.Count > 0)
{
string strSql = " ";
string CnnString = ConfigurationManager.AppSettings[ "SqlConnection "];
OleDbConnection conn = new OleDbConnection(CnnString);
conn.Open();
OleDbCommand myCmd = null;
for (int i = 0; i < myDs.Tables[0].Rows.Count; i++)
{
strSql = "insert into KH_Con(username,sex,usergs,bumen,zhiwu,shouji,tel,fox,mail,content) values ( ' ";
strSql += myDs.Tables[0].Rows[i].ItemArray[1].ToString() + " ', ' ";
strSql += myDs.Tables[0].Rows[i].ItemArray[2].ToString() + " ' ' ";
strSql += myDs.Tables[0].Rows[i].ItemArray[3].ToString() + " ' , ' ";
strSql += myDs.Tables[0].Rows[i].ItemArray[4].ToString() + " ', ' ";
strSql += myDs.Tables[0].Rows[i].ItemArray[5].ToString() + " ', ' ";
strSql += myDs.Tables[0].Rows[i].ItemArray[6].ToString() + " ', ' ";
strSql += myDs.Tables[0].Rows[i].ItemArray[7].ToString() + " ', ' ";
strSql += myDs.Tables[0].Rows[i].ItemArray[8].ToString() + " ', ' ";
strSql += myDs.Tables[0].Rows[i].ItemArray[9].ToString() + " ', ' ";
strSql += myDs.Tables[0].Rows[i].ItemArray[10].ToString() + " ', ) ";
try
{
myCmd = new OleDbCommand(strSql, conn);
myCmd.ExecuteNonQuery();
Label8.Text = " <script language=javascript> alert( '数据导入成功. '); </script> ";
}
catch
{
Label8.Text = " <script language=javascript> alert( '数据导入失败. '); </script> ";
}
}
conn.Close();
}
这是导入代码。
请大哥们帮帮忙啊。 小弟万分感谢,郁闷了一天了。!~
[解决办法]
OleDbConnection c = new OleDbConnection(@ "Provider=Microsoft.Jet.OLEDB.4.0; "+ "Data Source= "+filename+ ";Extended Properties= 'Excel 8.0;IMEX=1 ' ");