刚刚在msdn上看了一下有关RowDataBound()事件的一些文章.具体网址是:http://msdn2.microsoft.com/zh-cn/library/system.web.ui.webcontrols.templatefield.itemtemplate(VS.80).aspx . (msdn网站可能有点慢等等拉)
我运行了其中那个示例的代码但是好象没有达到预期的效果. 
在这个示例中
if (radio != null)
    {
      switch (e.Row.Cells[3].Text.Trim())// e.Row.Cells[3].Text.Trim()的值为空        
          case "business":
          radio.SelectedIndex = 0; 
          break;
之后我又在msdn上找了一些有关RowDataBound()事件的代码,网址是http://msdn2.microsoft.com/zh-cn/library/system.web.ui.webcontrols.gridview.rowdatabound(VS.80).aspx#Mtps_DropDownFilterText
但这个示例中  e.Row.Cells[1].Text 又不为空 比较了两个程序又没有什么不同的  就是在第一个示例中<asp:boundfield datafield="type" visible="false"/> 它把"type"绑定列的visible="false"了  之后我把visible="false"去掉了 又是正确的! 不知道是什么原因难道msdn出错了?

解决方案 »

  1.   

    楼主用的GridView吧,如果在Html中将GridView的某列的visible="false",如<asp:boundfield datafield="type" visible="false"/>,那么在事件中是取不到值的。所以一般我要隐藏GridView的某列,是在RowDataBound或者RowCreate事件中去设置,这样可以保证页面回发时取得被隐藏列的值。
      

  2.   

    那为什么在msdn上它可以在GridView中<asp:boundfield datafield="type" visible="false"/> 把visible设置为"false"呢?是MSND的出错了么?
      

  3.   

    这是msdn上的一个示例 难道它没有绑定么你可以看看它示例http://msdn2.microsoft.com/zh-cn/library/system.web.ui.webcontrols.templatefield.itemtemplate(VS.80).aspx 
      

  4.   

    这是MSDN上的原码你可以看看 
    我可是一点没有改哦!
    <%@ Page language="C#" %><script runat="server">  void TitleGridView_RowDataBound (Object sender, GridViewRowEventArgs e)
      {
        
        // Get the RadioButtonList control from the row.
        RadioButtonList radio = (RadioButtonList)e.Row.FindControl("TypeList");
        
        // Select the appropriate option button based on the value
        // of the Type field for the row. In this example, the Type
        // field values are stored in the hidden column in the 
        // GridView control.
        if (radio != null)
        {
          switch (e.Row.Cells[3].Text.Trim())
          {
            case "business":
              radio.SelectedIndex = 0; 
              break;        case "mod_cook":
              radio.SelectedIndex = 1; 
              break;        case "popular_comp":
              radio.SelectedIndex = 2; 
              break;        case "psychology":
              radio.SelectedIndex = 3; 
              break;        case "trad_cook":
              radio.SelectedIndex = 4; 
              break;        default:
              radio.SelectedIndex = 5; 
              break;
          }
        }
        
      }
      
    </script><html>
      <body>
        <form runat="server">
            
          <h3>TemplateField ItemTemplate Example</h3>      <!-- Populate the Columns collection declaratively. -->
          <!-- Create a custom TemplateField column that uses      -->
          <!-- two Label controls to display an author's first and -->
          <!-- last name in the same column.                       -->
          <asp:gridview id="TitleGridView" 
            datasourceid="TitleSqlDataSource" 
            autogeneratecolumns="false"
            onrowdatabound="TitleGridView_RowDataBound" 
            runat="server">
                    
            <columns>
              
              <asp:boundfield datafield="title"
                headertext="Title"/>
              
              <asp:boundfield datafield="price"
                dataformatstring="{0:c}"
                headertext="Price"/>  
                      
              <asp:templatefield headertext="Type">
                <itemtemplate>
                  <asp:radiobuttonlist id="TypeList"
                    datasourceid="TypeSqlDataSource"
                    datatextfield="type"
                    enabled="false"  
                    runat="server"/>  
                </itemtemplate>
              </asp:templatefield>
              
              <asp:boundfield datafield="type"
                visible="false"/>
                    
            </columns>
                    
          </asp:gridview>
                
          <!-- This example uses Microsoft SQL Server and connects -->
          <!-- to the Pubs sample database.                        -->
          <asp:sqldatasource id="TitleSqlDataSource"  
            selectcommand="SELECT [title], [price], [type] FROM [titles]"
            connectionstring="server=localhost;database=pubs;integrated security=SSPI"
            runat="server">
          </asp:sqldatasource>
          
          <asp:sqldatasource id="TypeSqlDataSource"  
            selectcommand="SELECT Distinct [type] FROM [titles]"
            connectionstring="server=localhost;database=pubs;integrated security=SSPI"
            runat="server">
          </asp:sqldatasource>
                
        </form>
      </body>
    </html>
      

  5.   

    没有看见么 connectionstring="server=localhost;database=pubs;integrated security=SSPI" 啊!
      

  6.   

    我知道,我说你那个数据表里有值么,都设置些什么值?这是不是SQL自带的数据表?
      

  7.   

    ...... 这肯定是SQL自带的表啊!!
      

  8.   

    visible=false后是asp.net认为不输出也就不生成当然取不到用datakey或(datarowview)e.row可以取到
      

  9.   


    visible属性只是表示隐藏或是否显示的属性.不是是否输出的属性.如果是这样微软的MSDN它会不知道么,它知道还会那么做么.
      

  10.   


    关于gridview隐藏列的问题网上提问多得很,如果用普通正常方法能取到,那么多程序员就不用问这个问题了