How to add Image [for up & down functionality] in data grid

.net , asp.net , db , java Kuwait
  • 13 years ago

    Hi all,

    I am a kind of newto ASP.NET and project requires for a functionality in the data grid to move columns based on the Database value . Say there is a number coming from Database which depends on this i need to display up /up&down/ down arrows based on number. I have not seen any examples related to use of images and this kind of function.

    Highly appreciate any help

    Regards

    Ben Beer

  • 13 years ago

    can you explain a little further with [quote]move columns based on the Database value[/quote] I'm not fully understanding what you are wanting to do here. Are you sure you mean columns?? .. and not rows??

    relating an image to a database value should not be too difficult since you could associate an image name with the value of the database 'number'

    for instance:  1.jpg; 2.jpg; 3.jpg  (not great for understanding but very simple)

    Joe 

     

  • 13 years ago

    Hi Joe,

    Appreciate your response. Its a kind of dorky of me You are right. I need to move rows up and down and not columns. I have not even come to that to be right. I have a another challenge being newbie to .NET stuff as of overall. I am still having problem understanding the datagrid working.

    My ultimate question would be [As being a java progammer for ever]

    - When happens when  You say "DataBinder.Eval(e.Item.DataItem, "object_key").ToString()" Code on the html side is below.

    <asp:TemplateColumn HeaderText="Object Name">
                  <ItemTemplate>
                   <asp:label width="250px" runat="server" Text='<%# DataBinder.Eval(Container.DataItem, "object_name") %>' ID="lblJobName" NAME="lblJobName"/>
                  </ItemTemplate>
                  <EditItemTemplate>
                   <asp:DropDownList id="ddlJobName" runat="server" width="250px" DataValueField="object_name" onchange="FieldUpdated(frmSchemaEditor.hdnJobFieldChanged)"></asp:DropDownList>
                  </EditItemTemplate>
                 </asp:TemplateColumn>' runat="server" width="250px">' runat="server" width="250px">

    > The current application uses the stored procs to retrieve data in rows. I am using template column to achieve this function. I am able to sucessfully retrieve the rows [before Edit is executed it works fine]. When i try to hit edit it gives Error and more like a thread abort error like below.

    =========================================

    System.Threading.ThreadAbortExceptionThread was being aborted.Thread was being aborted

    System.Threading.ThreadAbortException: Thread was being aborted. at System.Threading.Thread.AbortInternal() at System.Threading.Thread.Abort(Object stateInfo) at System.Web.HttpResponse.End() at System.Web.HttpResponse.Redirect(String url, Boolean endResponse) at System.Web.HttpResponse.Redirect(String url) at CSchemaEditor.dgJobDefs_ItemDataBound(Object sender, DataGridItemEventArgs e) in SchemaEditor.aspx.vb:line 1740 at System.Web.UI.WebControls.DataGrid.OnItemDataBound(DataGridItemEventArgs e) at System.Web.UI.WebControls.DataGrid.CreateItem(Int32 itemIndex, Int32 dataSourceIndex, ListItemType itemType, Boolean dataBind, Object dataItem, DataGridColumn[] columns, TableRowCollection rows, PagedDataSource pagedDataSource) at System.Web.UI.WebControls.DataGrid.CreateControlHierarchy(Boolean useDataSource) at System.Web.UI.WebControls.BaseDataList.OnDataBinding(EventArgs e) at System.Web.UI.WebControls.BaseDataList.DataBind() at CSchemaEditor.BindJobDefinitionData() in SchemaEditor.aspx.vb:line 1770 at CSchemaEditor.dgJobDefs_Edit(Object sender, DataGridCommandEventArgs e) in SchemaEditor.aspx.vb:line 1494

    =========================================

    As of i can get it, sorry it may be too basic for you.

    Current row consits of values from the Stored proc[table X] say ColumA, ColumnB and ColumnC displayed as table. I need to display a dropdown of list from Stored proc[table Y] when edited and save the selected value to the DB from dropdown. This is where i am stuck. I am doing some thing wrong here and i am getting this error.

     Am i on to right track or do i need more study before i move further. :-)

    Appreciate any direction.

     

     

     

     

  • 13 years ago

    Hi Joe,

     I finally got it working on the bound issue in datagrid. As i still need to proceed with Images function this is what i need to do.

     > I need to setup two image buttons some thing like Up and Down arrows depending on value obtained from DB, One down arrow if the value is top most (say 1)  and up and down arrows for (say 2 & 3) and one up arrow for the bottom most value (say 4) once the user clicks on one of them the value behind the db should be updated for that DB field.

    > User can not edit the columns until he clicks edit and once he clicks edit he will be able to change the row details. I belive the DataGridItemEventArgs will pick up the command and execute the action based on the values existing while i populate. 

    Appreciate your help and response..

    Ben.

  • 13 years ago

    Ben,

    Have a look at: http://aspnet.4guysfromrolla.com/articles/040502-1.aspx

    This is a good set of article's that will assist you in understanding the datagrid more thoroughly
    (very similar to the GridView)

    For your particular case, this is what I interpret from your description:

    You have a table in the database with some data in it...

    Field1  Field2  Field3
    1       ABC     Pluto
    2       DEF     Neptune
    3       GHI     Saturn
    4       JKL     Mars

    Field1 is used as a sort order.

    You return this data from a stored procedure that orders the data by Field1.
    The data is then displayed somewhat like:

            Field1  Field2  Field3
     >      1       ABC     Pluto
     <>     2       DEF     Neptune
     <>     3       GHI     Saturn
     <      4       JKL     Mars

    (> == down image; < == up image)
    This means that the very first row can only have the down image button and the very last row, an up image button. All other rows then have TWO image buttons - both up and down.

    This could be accomplished though the DataBound event on the DataGrid, whereby you check each row as its bound to the grid and load the appropriate image(s). Obviously this slows the grids processing - but whether this is an issue will depend upon how much data you have (and other factors).

    However, when you move the rows either up or down, how do you see the processing being handled as you go back and forth to the server? Are the values in Field1 always consistently sequential? (1, 2, 3, 4,...) For instance, (from the data above) lets say you click the down image associated with Field1 = 3. This means that it must change its value to 4 whilst at the same time changing the associated row Field1 value to 3. ie swap them. What happens if Field1 values are not sequential? Will you be doing this on each "edit" operation? Do you really need to do an edit operation for this? If so I'm assuming that there is some form of security mechanism that prevents certain users from editing rows.

    Of course, I may be way off the mark here - its always difficult to interpret requirements at this sort of communicative level. Much better on a white board. :)

    Joe

  • 13 years ago

    Hi Joe,

    Data looks like this more or less

    Field X   Field1  Field2  Field3
    alpha       1       ABC     Pluto
    beta         1       DEF     Neptune
    beta         2       DEL     Neptune
    Gamma   1       GHI      Saturn
    Gamma   2       GHJ     Saturn
    Gamma   3       GHK     Saturn
    Delta       1       JKL      Mars

    Field1 is used as a sort order.

    Yes the data from a stored procedure that orders the data by Field1.   The data is then displayed somewhat like:

           Field X   Field1  Field2  Field3
    n/a  alpha        1       ABC     Pluto
     >    beta         1       DEF     Neptune
     <    beta         2       DEL     Neptune
    >    Gamma     1       GHI     Saturn
    <>  Gamma     2       GHJ    Saturn
     <   Gamma     3       GHK   Saturn
    n/a  Delta        1       JKL     Mars 

    However, when you move the rows either up or down, how do you see the processing being handled as you go back and forth to the server? 

    > I am thinking of capturing the image button action and processing the information to refresh. I am thinkin it may be easy to use with out a edit function.

    Are the values in Field1 always consistently sequential? (1, 2, 3, 4,...) For instance, (from the data above) lets say you click the down image associated with Field1 = 3. This means that it must change its value to 4 whilst at the same time changing the associated row Field1 value to 3. ie swap them.

    > Yes i may need to write the functionality in the stored proc. Wish the code was a java code i could have written while half-asleep :-). I am still making some progress in VB .NET feels good anyway. 

     What happens if Field1 values are not sequential? Will you be doing this on each "edit" operation?

    > Once the values are refreshed always screen returns them sorted so i would not worry about that yet

    Do you really need to do an edit operation for this? If so I'm assuming that there is some form of security mechanism that prevents certain users from editing rows.

    > Yes i am thinking it would be better to do this funtionality with out editing and change the rest with edit function.

     Really Appreciate your help on it.

    Ben.

     

  • 13 years ago

    Ben, still a little confused. Shouldn't the resulting data returned from the db look like:

        Field X   Field1  Field2  Field3
    >    alpha        1       ABC     Pluto
    >    beta         1       DEF     Neptune
    >    Delta        1       JKL     Mars
    >    Gamma    1       GHI     Saturn
    <>   beta        2       DEL     Neptune
    <>   Gamma   2       GHJ     Saturn
    <    Gamma    3       GHK     Saturn

    if its sorted on Field1?

    I dont comprehend why you have n/a listed ? since the top row could be displaced (down) to "2" and likewise for Item with Field1 == "3" (displaced up)

    Joe 

     

    I agree: I think that porcessing the image action as a separate action is probably better than combining with the edit functionality. 

     

  • 13 years ago

    Hi Joe,

    Its Order by on the both columns X & 1. The user knows if he can send it up or down based on the column X. n/a will be displayed the columns who only have one row there is no need for the user interaction unless he adds another row which corresponds to field X.

    Thanks for suggestion i will have to ask the BA to change the design..

    Ben 

     

     

  • 13 years ago

    I must admit, I'm still a little confused by the functionality ... but as long as you've sorted it out then that's cool.

    Joe 

Post a reply

Enter your message below

Sign in or Join us (it's free).

Contribute

Why not write for us? Or you could submit an event or a user group in your area. Alternatively just tell us what you think!

Our tools

We've got automatic conversion tools to convert C# to VB.NET, VB.NET to C#. Also you can compress javascript and compress css and generate sql connection strings.

“A computer lets you make more mistakes faster than any other invention in human history, with the possible exceptions of handguns and tequila” - Mitch Ratcliffe