gridview(scrollview和gridview的区别)

本文目录
- scrollview和gridview的区别
- ASP.NET中Gridview控件的使用方法!!!
- gridview 怎样删除一行
- GridView有哪些属性
- Gridview里面的属性有哪些 都有什么用
- gridview是什么
- Visual Studio里的GridView控件用法
- 如何利用GridView控件实现查找功能
- 如何在GridView中实现多选
scrollview和gridview的区别
public class MyGridView extends GridView {
public MyGridView(Context context, AttributeSet attrs) {
super(context, attrs);
}
public MyGridView(Context context) {
super(context);
}
public MyGridView(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
}
@Override
public void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
int expandSpec = MeasureSpec.makeMeasureSpec(
Integer.MAX_VALUE 》》 2, MeasureSpec.AT_MOST);
super.onMeasure(widthMeasureSpec, expandSpec);
}
}
该自定义控件只是重写了GridView的onMeasure方法,使其不会出现滚动条,ScrollView嵌套ListView也是同样的道理,不再赘述。
XML布局代码
[html] view plain copy
《ScrollView Android:layout_height=“wrap_content“
Android:layout_width=“fill_parent“ android:id=“@+id/scroll_content“》
《com.yourclass.MyGridView xmlns:Android=“
ASP.NET中Gridview控件的使用方法!!!
不要用button Gridview 自身的模板化后的linkbutton 有一个e.CommandArgument 属性 《ItemTemplate》
《asp:LinkButton ID=“LinkButton1“ runat=“server“ CausesValidation=“false“
CommandName=“button“ Text=“获取行号“ CommandArgument=’《%# Container.DataItemIndex %》’
onclick=“LinkButton1_Click“》《/asp:LinkButton》
《/ItemTemplate》
《/asp:TemplateField》
CommandArgument=’《%# Container.DataItemIndex %》’ 这句话就是行号
然后在后台
int j = Convert.ToInt32(e.CommandArgument); //在rowdatacommand函数中写
Response.Write(“《script》window.confirm(’这是第“+ j +“ 行’)《/script》“)
点击哪行就显示几 //
gridview 怎样删除一行
源代码
《asp:GridView ID=“GridView2“ runat=“server“ DataSourceID=“SqlDataSource1“ DataKeyNames=“typeid“
AutoGenerateColumns=“False“ AllowSorting=“True“ AllowPaging=“True“ AutoGenerateEditButton=“True“
Width=“483px“ OnRowUpdating=“GridView2_RowUpdating“ OnRowDataBound=“GridView2_RowDataBound“
OnRowDeleting=“GridView2_RowDeleting“ OnRowCommand=“GridView2_RowCommand“》
DataKeyNames是你的主键
后台代码
protected void GridView1_RowDeleting(object sender, GridViewDeleteEventArgs e)
{
co = new common(); //数据库链接类
string sql = “Delete from [dbo].[T-InvestItem] where id=’“ + GridView1.DataKeys[e.RowIndex].Value + “’“;
co.Sql_ExecuteSql(sql);
}
GridView有哪些属性
GridView有两个,一个是System.Web.Ui.WebControls下面的,一个是System.Windows.Controls下面的,属性就比较多了,没必要一一列出来吧,你可以在VS的[视图]-》[对象浏览器]中输入“GridView”找到它,所有属性都能看到的。
希望对你有帮助,如有疑问请追问或是Hi
Gridview里面的属性有哪些 都有什么用
Gridview 是C#用户界面表格控件
具体属性如下:
可查看msdn详细介绍
具体属性如下:
AllowsColumnReorder :获取或设置一个值,该值指示 GridView 中的列是否可以通过拖放操作重新排序。
ColumnHeaderContainerStyle:获取或设置应用于列标题的样式。
ColumnHeaderContextMenu:获取或设置 GridView 的 ContextMenu。
ColumnHeaderStringFormat:获取或设置一个撰写字符串,该字符串指定如果 GridView 的列标题显示为字符串,应如何设置这些列标题的格式。
ColumnHeaderTemplate:获取或设置用于显示列标题的模板。
ColumnHeaderTemplateSelector:获取或设置为选择每个列标题所使用的模板提供逻辑的选择器对象。
ColumnHeaderToolTip:获取或设置当鼠标指针悬停在某个列标题上时显示的工具提示的内容。
Columns:获取为此 GridView 定义的 GridViewColumn 对象的集合。
DefaultStyleKey:获取 GridView 的默认样式的引用。(替代 ViewBase.DefaultStyleKey。)
DependencyObjectType:获取对此实例的 CLR 类型进行包装的 DependencyObjectType。 (从 DependencyObject 继承。)
Dispatcher :获取与此 DispatcherObject 关联的 Dispatcher。(从 DispatcherObject 继承。)
GridViewItemContainerStyleKey:获取一个键,该键引用为 GridView 中的每个 ListViewItem 定义的样式。
GridViewScrollViewerStyleKey:获取一个键,该键引用为 ScrollViewer 控件(该控件包含 GridView 显示的内容)定义的样式。
GridViewStyleKey:获取一个键,该键引用为 GridView 定义的样式。
IsSealed:获取一个指示此实例当前是否已密封 (只读)的值。 (从 DependencyObject 继承。)
ItemContainerDefaultStyleKey:获取对 GridView 中数据项的容器的默认样式的引用。(替代 ViewBase.ItemContainerDefaultStyleKey。)
gridview是什么
gridview,从英文去理解它,必尽是人家起的名。
grid是表格 小格子的意思
view是查看,显示的意思
整个就是合成词
意思就是用来显示数据的表格。
Visual Studio里的GridView控件用法
通过GridView 的 DataBound事件, 为每一行添加 点击事件:
Entity entity = e.Row.DataItem as Entity; //Entity是你绑定到GridView的对象
string workPath = entity.WordPath;
e.Row.Attribute.Add(“onclick“,“window.open(’“ + workPath + “’)“);
如何利用GridView控件实现查找功能
首先保证你装MSSQL然后将我的方法复制到你的代码中就可以直接运行了,我使用的MSSQL中默认的数据库Master,你可以自己修改
注意你的代码也需要引入using System.Data.SqlClient;这个空间。
你首先将一个TextBox、Button、GridView拖入你的代码,然后双击Button产生事件,将TestCon();写入,如下:
//按钮的事件
protected void Button1_Click1(object sender, EventArgs e)
{
TestCon();
}
然后在你代码页面直接复制下面的方法即可,
private void TestCon()
{
string strConn = “data source=localhost;initial catalog=master;user id=sa;password=“;
SqlConnection con = new SqlConnection(strConn);;
DataSet ds = new DataSet();
con.Open();
//自定义查询SQL字符串
string strTemp = TextBox.Text //需要查寻的数据,从TextBox中读取
string cmdtext = “select ’“+strTemp+“’ from spt_values“;
//数据库记录保存到字符串
//创建SqlDataAdapter数据适配器
SqlDataAdapter sda = new SqlDataAdapter(cmdtext, con);
//创建数据集
//填充数据集合(如下:填充进字符串表名Master)
sda.Fill(ds, “Master“);
GridView1.DataSource = ds;
GridView1.DataBind();
}
这样完全按照你的要求做出了简单查寻功能
如何在GridView中实现多选
GridView实现跨页多选,参考如下:
JS 前台:
//GridView中实现多选效果function CheckAllC(oCheckbox) {
var GridView1 = document.getElementById(’gvDataList’);
for (i = 1; i 《 gvDataList.rows.length; i++) {
GridView1.rows[i].cells.getElementsByTagName(“INPUT“).checked = oCheckbox.checked;
}
}
后台:
1:GridView翻页PageIndexChanging事件中调用获取多选主键信息,还需要判断一下,翻页之前是否已经有数据选中。具体方法如下:
方法如下:
#region 存储GridView翻页数据主键
/// 《summary》
/// 存储GridView翻页数据主键
/// 《/summary》
private void RememberOldValues()
{
Dictionary《string, string》 list = Session[“SelectedObject“] as Dictionary《string, string》;
if (list == null)
{
list = new Dictionary《string, string》();
}
foreach (GridViewRow row in gvDataList.Rows)
{
CheckBox cb = (CheckBox)row.FindControl(“chkSelect“);
string user = gvDataList.DataKeys[row.RowIndex].Value.ToString();
if (Session[“SelectedObject“] != null)
list = (Dictionary《string, string》)Session[“SelectedObject“]; //很重要
if (cb.Checked)
{
if (!list.ContainsKey(user))
{
list.Add(user, “null“);
}
}
else
{
if (list.ContainsKey(user))
{
list.Remove(user);
}
}
if (list != null && list.Count 》 0)
Session[“SelectedObject“] = list;
}
}
#endregion
附带GridView自带分页:
#region 分页
protected void gvDataList_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
RememberOldValues();
// 得到该控件
GridView theGrid = sender as GridView;
int newPageIndex = 0;
if (e.NewPageIndex == -3)
{
//点击了Go按钮
TextBox txtNewPageIndex = null;
//GridView较DataGrid提供了更多的API,获取分页块可以使用BottomPagerRow 或者TopPagerRow,当然还增加了HeaderRow和FooterRow
GridViewRow pagerRow = theGrid.BottomPagerRow;
if (pagerRow != null)
{
//得到text控件
txtNewPageIndex = pagerRow.FindControl(“txtNewPageIndex“) as TextBox;
}
if (txtNewPageIndex != null)
{
//得到索引
newPageIndex = int.Parse(txtNewPageIndex.Text) - 1;
}
}
else
{
//点击了其他的按钮
newPageIndex = e.NewPageIndex;
}
//防止新索引溢出
newPageIndex = newPageIndex 《 0 ? 0 : newPageIndex;
newPageIndex = newPageIndex 》= theGrid.PageCount ? theGrid.PageCount - 1 : newPageIndex;
//得到新的值
theGrid.PageIndex = newPageIndex;
//重新绑定
BindItems(0, NodeID, strSearch);
}
#endregion
2:点击提交按钮时,需要获取下GridView中的多选主键ID
#region 获取单选按钮选中的主键ID
/// 《summary》
/// 获取单选按钮选中的主键ID
/// 《/summary》
/// 《returns》《/returns》
private void GetPkID()
{
Dictionary《string, string》 list = Session[“SelectedObject“] as Dictionary《string, string》;
if (list == null)
{
list = new Dictionary《string, string》();
}
foreach (GridViewRow row in gvDataList.Rows)
{
CheckBox cb = (CheckBox)row.FindControl(“chkSelect“);
string user = gvDataList.DataKeys[row.RowIndex].Value.ToString();
if (cb.Checked)
{
if (!list.ContainsKey(user))
{
list.Add(user, “null“);
}
}
else
{
if (list.ContainsKey(user))
{
list.Remove(user);
}
}
}
ViewState[“SelectedObject“] = list;
}
#endregion

更多文章:
majority of(the majority of 和 a majority of的区别以及用法例句)
2026年10月11日 07:40
another time(another time和other time的区别)
2026年10月11日 05:00







