如何做到datagrid根据数据自动生成下拉条!

hanzhuangren 2009-04-28 10:35:08
如题!
...全文
161 12 打赏 收藏 转发到动态 举报
写回复
用AI写文章
12 条回复
切换为时间正序
请发表友善的回复…
发表回复
fdc123 2009-04-30
  • 打赏
  • 举报
回复
意思是跟WinFORM的DATAGRIDVIEW样的数据多了直接由个下拉条?
oiqio 2009-04-30
  • 打赏
  • 举报
回复
原来说的是竖滚动条。。。都以为是下拉列表呢,o(∩_∩)o...
anlianganl 2009-04-30
  • 打赏
  • 举报
回复
[Quote=引用 4 楼 junyi2003 的回复:]
Datagrid 外面加个Div就可以了

<div style="width:1024px;height:300px;overflow:auto;">
....DataGrid
</div>

--------
再不行的话,你就要自己重写一个自定义的DataGrid了。

前面这个方法我个人认为是最简单的。
[/Quote]
很不错,就用这个吧。
hanzhuangren 2009-04-30
  • 打赏
  • 举报
回复
还没有弄出来啊!迷茫!
abintianshen1 2009-04-29
  • 打赏
  • 举报
回复
楼主你弄出来了么?我现在就特别需要你说的这个
woailaji1 2009-04-28
  • 打赏
  • 举报
回复
一般我都是用GridView+DropDownList来实现。
如果你是初学者。建议你用SqlDataSource控件来配置数据源。

实现起来很简单。
GridView里添加类型为TemplateField列。
代码如下:
<asp:GridView ID="GridView1" runat="server">
<asp:TemplateField HeaderText="【下拉条】页眉名称">
<ItemTemplate>
<asp:DropDownList ID="DropDownList1" runat="server" DataSource='【绑定的SqlDataSource数据源】这里可以在【设计】模式下手动添加'>
</asp:DropDownList>

</ItemTemplate>
</asp:TemplateField>
</asp:GridView>

不知道您看懂了没
junyi2003 2009-04-28
  • 打赏
  • 举报
回复
这个是让表头不动的HTML原代码。因为DataGrid这个控件我不常在vs2008中用,所有到时候你自己Code一下就行

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"><head>
<style type="text/css">
<!--
body {
background: #FFF;
color: #000;
font: normal normal 12px Verdana, Geneva, Arial, Helvetica, sans-serif;
margin: 10px;
padding: 0
}

table, td, a {
color: #000;
font: normal normal 12px Verdana, Geneva, Arial, Helvetica, sans-serif
}

.td
{
nowrap:’’true’’;
}

div.tableContainer {
border: 1px solid #963;
height: 185px;
overflow: auto;
width: 100%;
}

/* WinIE 6.x needs to re-account for it’’s scrollbar. Give it some padding */
\html div.tableContainer/* */ {
padding: 0 16px 0 0
}


/* define width of table. IE browsers only */
/* if width is set to 100%, you can remove the width */
/* property from div.tableContainer and have the div scale */
div.tableContainer table {
float: left;
width: 100%
}

/* WinIE 6.x needs to re-account for padding. Give it a negative margin */
\html div.tableContainer table/* */ {
margin: 0 -16px 0 0
}


/* set table header to a fixed position. WinIE 6.x only */
/* In WinIE 6.x, any element with a position property set to relative and is a child of */
/* an element that has an overflow property set, the relative value translates into fixed. */
/* Ex: parent element DIV with a class of tableContainer has an overflow property set to auto */
thead.fixedHeader tr {
position: relative;
/* expression is for WinIE 5.x only. Remove to validate and for pure CSS solution */
top: expression(document.getElementById("tableContainer").scrollTop)
}



/* make the TH elements pretty */
thead.fixedHeader th {
background: #C96;
border-left: 1px solid #EB8;
border-right: 1px solid #B74;
border-top: 1px solid #EB8;
font-weight: normal;
padding: 4px 3px;
text-align: center
}

/* make the A elements pretty. makes for nice clickable headers */
thead.fixedHeader a, thead.fixedHeader a:link, thead.fixedHeader a:visited {
color: #FFF;
display: block;
text-decoration: none;
width: 100%
}

/* make the A elements pretty. makes for nice clickable headers */
/* WARNING: swapping the background on hover may cause problems in WinIE 6.x */
thead.fixedHeader a:hover {
color: #FFF;
display: block;
text-decoration: underline;
width: 100%
}



/* make TD elements pretty. Provide alternating classes for striping the table */
/* http://www.alistapart.com/articles/zebratables/ */
tbody.scrollContent td, tbody.scrollContent tr.normalRow td {
background: #FFF;
border-bottom: 1px solid #EEE;
border-left: 1px solid #EEE;
border-right: 1px solid #AAA;
border-top: 1px solid #AAA;
padding: 2px 3px
}

tbody.scrollContent tr.alternateRow td {
background: #EEE;
border-bottom: 1px solid #EEE;
border-left: 1px solid #EEE;
border-right: 1px solid #AAA;
border-top: 1px solid #AAA;
padding: 2px 3px
}


-->
</style>
</head><body>
<div id="tableContainer" class="tableContainer" style="width:900px;">
<table border="0" cellpadding="0" cellspacing="0" width="100%" class="scrollTable">
<thead class="fixedHeader">
<tr>
<th><a href="#">Header 1</a></th>
<th><a href="#">Header 2</a></th>
<th><a href="#">Header 3</a></th>
<th><a href="#">Header 4</a></th>
<th><a href="#">Header 5</a></th>
<th><a href="#">Header 6</a></th>
<th><a href="#">Header 7</a></th>
</tr>
</thead>
<tbody class="scrollContent">
<tr>
<td>Cell Content 1</td>
<td>Cell Content 2</td>
<td>Cell Content 3</td>
<td>Cell Content 4</td>
<td>Cell Content 5</td>
<td>Cell Content 6</td>
<td>Cell Content 7</td>
</tr>
<tr>
<td>More Cell Content 1</td>
<td>More Cell Content 2</td>
<td>More Cell Content 3</td>
<td>More Cell Content 4</td>
<td>More Cell Content 5</td>
<td>More Cell Content 6</td>
<td>More Cell Content 7</td>
</tr>
<tr>
<td nowrap>Even More Cell Content 1 Even More Cell Content Even More Cell Content </td>
<td nowrap>Even More Cell Content 2</td>
<td nowrap>Even More Cell Content 3</td>
<td nowrap>Even More Cell Content 4</td>
<td nowrap>Even More Cell Content 5</td>
<td nowrap>Even More Cell Content 6</td>
<td nowrap>Even More Cell Content 7</td>
</tr>
<tr>
<td>And Repeat 1</td>
<td>And Repeat 2</td>
<td>And Repeat 3</td>
<td>And Repeat 4</td>
<td>And Repeat 5</td>
<td>And Repeat 6</td>
<td>And Repeat 7</td>
</tr>
<tr>
<td>And Repeat 1</td>
<td>And Repeat 2</td>
<td>And Repeat 3</td>
<td>And Repeat 4</td>
<td>And Repeat 5</td>
<td>And Repeat 6</td>
<td>And Repeat 7</td>
</tr>
<tr>
<td>And Repeat 1</td>
<td>And Repeat 2</td>
<td>And Repeat 3</td>
<td>And Repeat 4</td>
<td>And Repeat 5</td>
<td>And Repeat 6</td>
<td>And Repeat 7</td>
</tr> <tr>
<td>And Repeat 1</td>
<td>And Repeat 2</td>
<td>And Repeat 3</td>
<td>And Repeat 4</td>
<td>And Repeat 5</td>
<td>And Repeat 6</td>
<td>And Repeat 7</td>
</tr>
<tr>
<td>And Repeat 1</td>
<td>And Repeat 2</td>
<td>And Repeat 3</td>
<td>And Repeat 4</td>
<td>And Repeat 5</td>
<td>And Repeat 6</td>
<td>And Repeat 7</td>
</tr>
<tr>
<td>And Repeat 1</td>
<td>And Repeat 2</td>
<td>And Repeat 3</td>
<td>And Repeat 4</td>
<td>And Repeat 5</td>
<td>And Repeat 6</td>
<td>And Repeat 7</td>
</tr>
<tr>
<td>And Repeat 1</td>
<td>And Repeat 2</td>
<td>And Repeat 3</td>
<td>And Repeat 4</td>
<td>And Repeat 5</td>
<td>And Repeat 6</td>
<td>And Repeat 7</td>
</tr>
<tr>
<td>And Repeat 1</td>
<td>And Repeat 2</td>
<td>And Repeat 3</td>
<td>And Repeat 4</td>
<td>And Repeat 5</td>
<td>And Repeat 6</td>
<td>And Repeat 7</td>
</tr>
<tr>
<td>And Repeat 1</td>
<td>And Repeat 2</td>
<td>And Repeat 3</td>
<td>And Repeat 4</td>
<td>And Repeat 5</td>
<td>And Repeat 6</td>
<td>And Repeat 7</td>
</tr>

<tr>
<td>And Repeat 1</td>
<td>And Repeat 2</td>
<td>And Repeat 3</td>
<td>And Repeat 4</td>
<td>And Repeat 5</td>
<td>And Repeat 6</td>
<td>And Repeat 7</td>
</tr>
<tr>
<td>And Repeat 1</td>
<td>And Repeat 2</td>
<td>And Repeat 3</td>
<td>And Repeat 4</td>
<td>And Repeat 5</td>
<td>And Repeat 6</td>
<td>And Repeat 7</td>
</tr>
</tbody>
</table>
</div>
</body></html>
junyi2003 2009-04-28
  • 打赏
  • 举报
回复
Datagrid 外面加个Div就可以了

<div style="width:1024px;height:300px;overflow:auto;">
....DataGrid
</div>

--------
再不行的话,你就要自己重写一个自定义的DataGrid了。

前面这个方法我个人认为是最简单的。
woailaji1 2009-04-28
  • 打赏
  • 举报
回复
首先我要说的是在WEB中好像真的是没有datagrid控件。常用的我只知道3个。GirdView,Repeater,DataList
这3个都能实现根据数据下拉
hanzhuangren 2009-04-28
  • 打赏
  • 举报
回复
我要的是WEB界面的!
zealot1021 2009-04-28
  • 打赏
  • 举报
回复
先拖一个下拉条,加载上数据
然后可以
dgvStockPlan.controls.Add(zfComboBox1);//zfComboBox1为下拉框,dgvStockPlan是gridView

Rectangle rect = this.dgvStockPlan.GetCellDisplayRectangle(this.dgvStockPlan.CurrentCell.ColumnIndex, this.dgvStockPlan.CurrentCell.RowIndex, false);
this.zfComboBox1.Left = rect.Left;
this.zfComboBox1.Top = rect.Top;
this.zfComboBox1.Width = rect.Width;
this.zfComboBox1.Height = rect.Height;
this.zfComboBox1.Visible = true;
在gridView里重新绘制它
hanzhuangren 2009-04-28
  • 打赏
  • 举报
回复
楼上谢谢你!可是我要说的不是眉目下拉!是所有的数据要下拉!

就是类似这里留言一样,文字多了!就自动有个滚动条了!可以滚动看数据!
可能是我描述不够造成误解了!不好意思!

111,126

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Creator Browser
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧