1

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 dynamically 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

1
  • CStr()? Did you mean to tag this as VB, not C#? Commented Feb 18, 2011 at 2:09

1 Answer 1

1

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();
}
Sign up to request clarification or add additional context in comments.

1 Comment

I appreciate your effort to support me but I am destined to solve my problem the other way. I fetched the data from the database on datatable, then add the the 7th column to datatable, then insert values of rows of the 7th column onrowdatabaound()...and finally change the datasource of the gridview to the dataset/datatable. ....The task I have to finish now is to handle sorting, deleting , paging, cancel etc events by hardcoding. If I need assistance on that...I hope you will be at my disposal.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.