62,053
社区成员
发帖
与我相关
我的任务
分享
public class DB
{
public DB()
{
}
public static DataSet GetData()
{
SqlConnection con = new SqlConnection(ConfigurationManager.AppSettings["drpConnectionString"].ToString());
string strsql = "SELECT TOP (5) CNTRCD, CNTRLN, CNTRSN FROM DIVA.M_COUNTRY";
SqlDataAdapter adp = new SqlDataAdapter(strsql, con);
DataSet ds = new DataSet();
adp.Fill(ds);
return ds;
}
}
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
this.GridView3.DataSourceID = ObjectDataSource1.ID;
//this.GridView3.DataKeyNames = dataKey;
this.GridView3.AutoGenerateColumns = true;
this.GridView3.DataBind();
}
}
protected void GridView3_RowCreated(object sender, GridViewRowEventArgs e)
{
e.Row.Cells[0].Visible = false;
}
<asp:ObjectDataSource ID="ObjectDataSource1" runat="server" SelectMethod="GetData"
TypeName="DB"></asp:ObjectDataSource>
<asp:GridView ID="GridView3" runat="server" OnRowCreated="GridView3_RowCreated">
</asp:GridView>
protected void GridView1_RowCreated(object sender, GridViewRowEventArgs e)
{
e.Row.Cells[0].Visible = false;
}