gridview edittemplate不显示内容

时间:2010-01-05 22:04:52

标签: asp.net gridview

我有三个列名称,比率,类别的网格视图

我也在这里使用ajax rate和edittemplate中的一个下拉列表,它与sqldatasource绑定。

但是当点击编辑时,它没有显示下拉列表。

请帮助解决这个问题。

代码是

<asp:gridview id="GVTweet" runat="server" allowpaging="True" allowsorting="True"
    autogeneratecolumns="False" gridlines="None" pagesize="15" width="700px" onselectedindexchanged="GVTweet_SelectedIndexChanged"
    onrowcancelingedit="GVTweet_RowCancelingEdit" onrowediting="GVTweet_RowEditing"
    onrowupdated="GVTweet_RowUpdated" onrowupdating="GVTweet_RowUpdating">
        <HeaderStyle />
        <AlternatingRowStyle Height="70px" />
        <RowStyle Height="70px" />
        <Columns>
            <asp:TemplateField HeaderImageUrl="~/images/twet1.png" HeaderText="Tweets" 
            ItemStyle-Height="70px">
            <ItemTemplate>
                <table border="0" cellpadding="0" cellspacing="0" width="auto">
                    <tr style="width:400px;">
                        <td align="left" style="height:70px;" valign="top">
                        <span class="box_imag">
                        <asp:Image ID="ScreenImage0" runat="server" height="50" 
                            ImageUrl='<%#DataBinder.Eval(Container.DataItem,"ImageUrl")%>' width="50" />
                        </span><span class="box_cont">
                        <asp:Label ID="lblId" runat="server" 
                            Text='<%#DataBinder.Eval(Container.DataItem, "id")%>' Visible="false">
                        </asp:Label>
                        <div>
                        <strong>
                            <a href="javascript:void(0)" 
                                onclick='setscreenname(&#039;<%#DataBinder.Eval(Container.DataItem, "ScreenName")%>&#039;)' 
                                rel="external">
                            <asp:Label ID="lblScreenName0" runat="server" 
                                Text='<%#DataBinder.Eval(Container.DataItem, "ScreenName")%>'></asp:Label>
                            </a>
                        </strong>
                        <asp:Label ID="lblText0" runat="server" 
                            Text='<%#DataBinder.Eval(Container.DataItem, "Text")%>'></asp:Label>
                        </div>
                        <div class="meta">
                            <asp:Label ID="lblDate0" runat="server" 
                            Text='<%#DataBinder.Eval(Container.DataItem, "Date")%>'></asp:Label>
                        </div>
                        </span>
                        </td>
                    </tr>
                </table>
            </ItemTemplate>
            </asp:TemplateField>
            <asp:TemplateField HeaderImageUrl="~/images/rate1.png" 
                HeaderStyle-CssClass="headerCss1" HeaderText="Rate(1-5)" 
                SortExpression="Rating" >
            <ItemTemplate>
                <table border="0" cellpadding="0" cellspacing="0" width="auto">
                    <tr style="width:150px;" valign="top" >
                        <td style="height:70px;">
                            <asp:UpdatePanel ID="updtpnlTweet0" runat="server">
                                <ContentTemplate>
                                    <cc1:Rating ID="rateTweet" runat="server" CurrentRating='<%# Bind("Rating") %>' 
                                        EmptyStarCssClass="empatyStarRating" FilledStarCssClass="filledStarRating" 
                                        MaxRating="5" onchanged="rateTweet_Changed" StarCssClass="ratingStar" 
                                        WaitingStarCssClass="savedStarRating">
                                    </cc1:Rating>
                                </ContentTemplate>
                            </asp:UpdatePanel>
                        </td>
                    </tr>
                </table>
            </ItemTemplate>
            </asp:TemplateField>
            <asp:TemplateField HeaderImageUrl="~/images/category1.png" 
                    HeaderStyle-CssClass="headerCss2" HeaderStyle-Width="148px" 
                    HeaderText="Categorize It" ItemStyle-CssClass="iteamHeader2">                                           
            <ItemTemplate>
                <table width="auto" border="0" cellspacing="0" cellpadding="0">
                    <tr align="center" valign="top" style="width:150px;" >
                        <td align="center" valign="top" style="height:70px; float:left;" >                            
                            <asp:Label ID="lblid1" runat="server" Text='<%#DataBinder.Eval(Container.DataItem,"CategoryName")%>' ></asp:Label>
                        </td>
                    </tr>
                </table>
            </ItemTemplate>                                        
            <EditItemTemplate>
                <asp:DropDownList ID="ddldivcategory" runat="server" Width="100px" CssClass="dropdowntweet" 
                    DataSourceID="SqlDataSource1" DataTextField="CategoryName" DataValueField="CategoryId" >
                                </asp:DropDownList>                   
           </EditItemTemplate>
           </asp:TemplateField>                                    
        <asp:CommandField ShowEditButton="True" />
    </Columns>
</asp:gridview>

3 个答案:

答案 0 :(得分:0)

尝试在gridview上声明DataKeyNames属性。

<asp:GridView ID="GVTweet" runat="server" DataKeyNames="PrimaryKeyName"...

答案 1 :(得分:0)

像这样使用并更改数据源解决了我的问题

答案 2 :(得分:0)

试试这个

    protected void GVTweet_RowEditing(object sender, GridViewEditEventArgs e)
    {
            GVTweet.EditIndex = e.NewEditIndex;

            //Load Grid
    }

<asp:gridview id="GVTweet" runat="server" allowpaging="True" allowsorting="True"
autogeneratecolumns="False" gridlines="None" pagesize="15" width="700px"     onselectedindexchanged="GVTweet_SelectedIndexChanged"
onrowcancelingedit="GVTweet_RowCancelingEdit" onrowediting="GVTweet_RowEditing"
onrowupdated="GVTweet_RowUpdated" onrowupdating="GVTweet_RowUpdating">