开发者

Adding Column to GridView data source and bind data to it at run time, C#

I am working on a task which requires binding data to a gridview which has 7 columns. Six columns of the gridview are binded to dataset from a database with sql command... I need to bind the last column dyna开发者_JS百科mically at run time to a data which comes from file at run time. Is there a mechanism to add 7th column to datasource at run time and then bind it's value? . .

 e.Row.Cells(7).Text = f.Name.ToLower.Replace(CStr(DataBinder.Eval(e.Row.DataItem, "LicenseName")).ToLower, "").Replace(".7z", "").Trim

. . this is how i got the value


You need a template column, like this :

<Columns>
    ...
     ...

    <asp:TemplateField>
        <ItemTemplate>
            <asp:Label ID="lblSeventhCol" runat="server" 
                ondatabinding="lblSeventhCol_DataBinding"></asp:Label>
        </ItemTemplate>
    </asp:TemplateField>
</Columns>

and

protected void lblSeventhCol_DataBinding(object sender, EventArgs e)
{
    (sender as Label).Text = GetDynamicData();
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜