思路就是点击时通过__doPostBack执行服务器事件。前台代码
<asp:TemplateField><ItemTemplate>
                                <asp:Button 
                                ID="btnShowDetail" 
                                runat="server"
                                Text='<%# Eval("fName") %>' 
                                CssClass="btnNoBorder" 
                                OnClick="btnShowDetail_Click">
                                </asp:Button> 
</ItemTemplate></asp:TemplateField>后台
protected void gvFriendList_RowDataBound(object sender, GridViewRowEventArgs e)
    { if (gvr.RowType == DataControlRowType.DataRow)
        {
Button btn = (Button)gvr.FindControl("btnShowDetail");
            
            gvr.Attributes.Add("onclick","__doPostBack('" + btn.ClientID + "','');");
        }
}
}这是FF中查看生成的代码
<tr onclick="__doPostBack('gvFriendList_ctl03_btnShowDetail','');">
<td>
                                <input id="gvFriendList_ctl03_ckBox" type="checkbox" name="gvFriendList$ctl03$ckBox" />
                            </td><td>                                <input type="submit" name="gvFriendList$ctl03$btnShowDetail" value="朋友" id="gvFriendList_ctl03_btnShowDetail" class="btnNoBorder" />
                            </td>
</tr>
为什么点击没效果呢

解决方案 »

  1.   

    还有个问题//合法用户
            if (Membership.ValidateUser(name, psw))
            {
                //取得 登录用户的唯一ID
                ForMoreApplication.LoginUserId = ForMoreApplication.GetPageUserId(name);ForMoreApplication.LoginUserId是个全局静态的变量,在这初始化后,做为条件来取数据库中的数据 。在哪设置一下可以让有效时间长点,我现在数据一会就取不到了……还得重新登录
      

  2.   

    在gridview中不要使用按钮的单击事件,而使用gridview的RowCommand事件(需要设置按钮的CommandName属性)
    <asp:TemplateField><ItemTemplate>
    <asp:Button
    ID="btnShowDetail"
    runat="server"
    Text='<%# Eval("fName") %>'
    CssClass="btnNoBorder"
    CommandName="save">
    </asp:Button>
    </ItemTemplate></asp:TemplateField>然后在gridview的RowCommand这样去判断是哪个按钮点击的
    if(e.CommondName == "save")
      

  3.   

    ForMoreApplication.LoginUserId是个全局静态的变量,在这初始化后,做为条件来取数据库中的数据 。在哪设置一下可以让有效时间长点,我现在数据一会就取不到了……还得重新登录
    -------------------------------
    你这个是ForMoreApplication.LoginUserId是写在哪里的,你直接保存到session中好点。session["LoginUserId"] = ForMoreApplication.GetPageUserId(name);
    取id:
    string strId = session["LoginUserId"];
      

  4.   

    Membership不是比SESSION好用点吗用了Membership 本来以为可以不用SESSION……
      

  5.   

    AK-47   改成RowCommand也没用,一样的效果
      

  6.   

    要注册gridview的RowCommand事件,并设置按钮的commandName
      

  7.   

    OnRowCommand="gvFriendList_RowCommand" ------------------------------<ItemTemplate>
                                    <asp:Button 
                                    ID="btnShowDetail" 
                                    runat="server"
                                    Text='<%# Eval("fName") %>' 
                                    CssClass="btnNoBorder" 
                                    CommandName="ShowDetail">
                                    </asp:Button>
                                </ItemTemplate>-------------------------------
    protected void gvFriendList_RowCommand(object sender, GridViewCommandEventArgs e)
        {
            fName.Text = e.CommandName;
        }
    -----------------
    但单击还是没效果
      

  8.   

    以前我做的关于__doPostBack()的例子,你看有用你就改改:
    HTML:
    <Script language=javascript>
    function linksort(cid)
    {
    //店面编号
    if(cid=="linkbtn")
    {
    __doPostBack("LinkButton1","LinkButton1_Click");
    }
    }
    </script><html>
    ...
    <asp:BoundColumn DataField="LinkCount" HeaderText="...onClick='linksort(this.id)'">
    </html>------------------------------------------------------------------
    后台C#在private void LinkButton1_Click(object sender, System.EventArgs e){}
    事件里你想怎么写就怎么写吧
      

  9.   

    __doPostBack()必须是和LinkButton控件组合使用 别的控件不行
      

  10.   

    LinkButton 好家伙   啥也没了……
    我的Button还能触发gvFriendList_RowCommand事件,现在是什么也没有了
    长期郁闷中
      

  11.   

    Button肯定能触发gvFriendList_RowCommand事件啊
    要用CheckBox就肯定不能了
      

  12.   

    你意思是说 我LinkBtn还要自己写事件 不用RowCommand
      

  13.   

    RowCommand这个是模板列事件
    你要用HTML控件调用后台C#事件的话 肯定要用__doPostBack()
    说白了 要是HTML控件直接调用后台web控件事件是不可能的  除非借助一下想LinkButton这样的控件(等于就是当你点击了HTML控件的同时也点击了LinkButton控件,同时也调用了写在C#中LinkButton的事件)。。
    就是这么回事,毕竟你的HTML控件不是放在里模板里了吗?
      

  14.   

    我上面不是给你例子了吗
    虽然你HTML控件在模板中 但不能用RowCommand事件因为RowCommand事件只有Button会触发假如你模板列中放了CheckBox,RadioButton类似的控件(就算你把AutoPostBack改成了true) 也不会触发RowCommand事件,还照样要在:
        protected void RadioButton1_CheckedChanged(object sender, EventArgs e)
        {    }
        protected void CheckBox1_CheckedChanged(object sender, EventArgs e)
        {    }
    这两个事件中写 ,也不能在RowCommand事件中写
      

  15.   

    不信你自己在RowCommand那加个断点试试
    到底那些控件会触发RowCommand事件
      

  16.   

    <tr onclick="__doPostBack('gvFriendList_ctl03_btnShowDetail','');">
    <td>
    <input id="gvFriendList_ctl03_ckBox" type="checkbox" name="gvFriendList$ctl03$ckBox" />
    </td><td><input type="submit" name="gvFriendList$ctl03$btnShowDetail" value="朋友" id="gvFriendList_ctl03_btnShowDetail" class="btnNoBorder" />
    </td>
    </tr>
    你说这个为什么不能触发呢,我已经有onclick="__doPostBack('gvFriendList_ctl03_btnShowDetail','');-----------
    Button也试了  LinkButton也试了,但问题还是没解决……
      

  17.   

    <tr onclick=
    tr里也有 onClick事件?
      

  18.   

    既然你用__doPostBack调用了后台的事件
    你调用后台的哪个事件 就应该在哪个web控件的Click事件中写,反正以前我多是这么做的
    没出过问题,用的全是LinkButton  也是在LinkButton1_Click事件中写的
      

  19.   

    自己到GridView里试下再说吧……